TimePickerDialog in spinner mode

14,196

use this code show time picker as spinner

    public void showCustomTimePicker()
    {

          final Calendar myCalender = Calendar.getInstance();
          int hour = myCalender.get(Calendar.HOUR_OF_DAY);
          int minute = myCalender.get(Calendar.MINUTE);


            TimePickerDialog.OnTimeSetListener myTimeListener = new TimePickerDialog.OnTimeSetListener() {
                @Override
                public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                    if (view.isShown()) {
                        myCalender.set(Calendar.HOUR_OF_DAY, hourOfDay);
                        myCalender.set(Calendar.MINUTE, minute);

                    }
                }
            };
            TimePickerDialog timePickerDialog = new TimePickerDialog(getActivity(), android.R.style.Theme_Holo_Light_Dialog_NoActionBar, myTimeListener, hour, minute, true);
            timePickerDialog.setTitle("Choose hour:");
            timePickerDialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
            timePickerDialog.show();
     }
Share:
14,196
Admin
Author by

Admin

Updated on June 09, 2022

Comments

  • Admin
    Admin about 2 years

    In my project, I use TimepickerDialog to show the time in a TextView. My Timepickerdialog is shown as a clock, but I want it shown as a spinner. How can I do this?

  • Admin
    Admin over 5 years
    Thanks, but I have a timePickerDialog, not a timePicker
  • Rohit5k2
    Rohit5k2 over 5 years
    @zahras: Use a theme that used spinner such as android.R.style.Theme_Holo_Light_Dialog
  • Vadim Kotov
    Vadim Kotov almost 5 years
    android.R.style.Theme_Holo_Light_Dialog is deprecated in API 28.
  • Vadim Kotov
    Vadim Kotov almost 5 years
    android.R.style.Theme_Holo_Light_Dialog_NoActionBar is deprecated in API 28.
  • Jeremiah
    Jeremiah over 4 years
    Is there a non-deprecated theme that uses the spinner?