ghstefano
ghstefano

Reputation: 181

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
    }
}

Upvotes: 13

Views: 7632

Answers (1)

NhatVM
NhatVM

Reputation: 2124

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

Upvotes: 4

Related Questions