显示TimePicker的问题:只能选择当前时间

时间:2016-10-27 11:34:32

标签: android android-timepicker

我想显示TimePicker所有时段可供选择。但对我来说,只有当前时间之后的时段可供选择。

请检查我的代码。

        final Calendar now = Calendar.getInstance();
        TimePickerDialog timePickerDialog = new TimePickerDialog();
        timePickerDialog.initialize(new TimePickerDialog.OnTimeSetListener() {
            @Override
            public void onTimeSet(RadialPickerLayout view, int hourOfDay, int minute, int second) {
                now.set(Calendar.HOUR_OF_DAY, 0);
                now.set(Calendar.MINUTE, 0);
                now.set(Calendar.SECOND, 0);
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("hh:mm a");
                String selectedDateString = simpleDateFormat.format(now.getTime());


                tvTimePicker.setText(selectedDateString);


            }
        }, now.get(Calendar.HOUR_OF_DAY), now.get(Calendar.MINUTE), now.get(Calendar.SECOND), false);

        Calendar minNowCalendar = Calendar.getInstance();
        timePickerDialog.setMinTime(minNowCalendar.get(Calendar.HOUR_OF_DAY), minNowCalendar.get(Calendar.MINUTE), minNowCalendar.get(Calendar.SECOND));


        timePickerDialog.show(getActivity().getFragmentManager(),"Key");

1 个答案:

答案 0 :(得分:1)

删除此行:

timePickerDialog.setMinTime(minNowCalendar.get(Calendar.HOUR_OF_DAY), minNowCalendar.get(Calendar.MINUTE), minNowCalendar.get(Calendar.SECOND));