Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TimePickerDialog in spinner mode

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?

like image 699
zahra s Avatar asked Nov 26 '22 19:11

zahra s


1 Answers

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();
     }
like image 200
Bhuvaneshwaran Vellingiri Avatar answered Dec 07 '22 23:12

Bhuvaneshwaran Vellingiri