Android - How to programmatically change timepicker mode?

亡梦爱人 提交于 2019-12-23 07:38:07

问题


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

回答1:


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



来源:https://stackoverflow.com/questions/27277338/android-how-to-programmatically-change-timepicker-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!