I have implemented the Android time picker according to the android dev doc, and everything works fine, but I am having a strange bug with it. I searched for it a lot and didn't find anything so, I am asking here.
Here is the code for it:
class TimePickerFragment extends DialogFragment
implements TimePickerDialog.OnTimeSetListener {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current time as the default values for the picker
final Calendar c = Calendar.getInstance();
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);
// Create a new instance of TimePickerDialog and return it
return new TimePickerDialog(getActivity(), this, hour, minute,
DateFormat.is24HourFormat(getActivity()));
}
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
// Do something with the time chosen by the user
if (hourOfDay < 10) {
startTime.setText("0" + Integer.toString(hourOfDay) + ":" + Integer.toString(minute));
} else if (minute < 10) {
startTime.setText(Integer.toString(hourOfDay) + ":0" + Integer.toString(minute));
} else if (hourOfDay < 10 && minute < 10) {
startTime.setText("0" + Integer.toString(hourOfDay) + ":0" + Integer.toString(minute));
} else if (minute == 0) {
startTime.setText(Integer.toString(hourOfDay) + ":00");
} else
startTime.setText(Integer.toString(hourOfDay) + ":" + Integer.toString(minute));
}
}
Does anyone knows how to fix this?
I faced with the same issue on Samsung devices (Galaxy S5 and S6 in my case). I found that on this devices title is added by system and to hide that title all you need to do is to set it to null by your own.
TimePickerDialog dialog = new TimePickerDialog(getActivity(), this, hour, minute, false);
dialog.setTitle(null);