0

I'm working with the timepicker dialouge here but for some reason which i don't understand, i couldn't change the mode of the time picker to that of AM_PM mode I have tried the code timepicker.setIs24HourView(false); Here is my code

onCreate(..){
button.onClickListe..(new...(){
showTimePickerDialog();
});}


 public static 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
        return new TimePickerDialog(getActivity(), this, hour, minute,
                true);
    }

    public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
       view.setIs24HourView(false);//TODO not working <-------- This code is not working here
        setTimeString(hourOfDay, minute, 0);

        timeView.setText(timeString);
    }
}


`private void showTimePickerDialog() {
    DialogFragment newFragment = new TimePickerFragment();
    newFragment.show(getFragmentManager(), "timePicker");
}`}
silverFoxA
  • 4,549
  • 7
  • 33
  • 73

1 Answers1

0

Check last parameter in TimePickerDialog constructor which is for 24 hours format, So disable 24 hours format with passing false value for last parameter :

return new TimePickerDialog(getActivity(), this, hour, minute,false);
Haresh Chhelana
  • 24,720
  • 5
  • 57
  • 67