I have to show the time picker in hh:mm format on Click the edit text.So that I had used the below code.
MainActivity.java:
e6.set
You can Try this way...
mTimePicker = new TimePickerDialog(AddFlight.this, new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker timePicker, int selectedHour, int selectedMinute) {
String formattedTime = "";
String sHour = "00";
// converting hour to tow digit if its between 0 to 9. (e.g. 7 to 07)
if(selectedHour < 10)
sHour = "0"+selectedHour;
else
sHour = String.valueOf(selectedHour);
e6.setText(sHour + ":" + selectedMinute);
}
}, hour, minute, true);
Just set the text to "%02d:%02d" as follows:
e6.setText(String.format("%02d:%02d", selectedHour, selectedMinute));
Hope so this might help you
Just now I had referred this post and change the single line:
this line
e6.setText(selectedHour + ":" + selectedMinute);
to
e6.setText(String.format("%02d:%02d", selectedHour, selectedMinute));
Just use this method,
private String getDD(int num) {
return num > 9 ? "" + num : "0" + num;
}