Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - How to programmatically change timepicker mode?

I had a look at this answer but using the APIs timepickerdialog (code below) I would like to set timePickerMode property in my class .java is it possible?

    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 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
    }
}
like image 701
ghstefano Avatar asked Dec 03 '14 16:12

ghstefano


People also ask

How to open TimePicker on edittext click in Android?

TimePickerDialog timePickerDialog = new TimePickerDialog(MainActivity. this, new TimePickerDialog. OnTimeSetListener() { @Override public void onTimeSet(TimePicker timePicker, int hourOfDay, int minutes) { } }, 0, 0, false); 9- Finally add the following code to be able to see TimePickerDialog appear in the screen.


1 Answers

I have the same issue. Then I read TimePicker source code. I think we can't change timepicker mode in .java file. Google set mode of TimePicker in contructor method: http://prntscr.com/blkkkd

like image 107
NhatVM Avatar answered Sep 28 '22 01:09

NhatVM