Search code examples
androidandroid-timepicker

Android : Is It Possible To Show Only Quaters in Time Picker ? 00 : 15 : 30 :45


I need to show only [00 , 15 , 30 ,45] in time picker i have searched but couldn't find anything , Does any one have idea how to achieve this ?

Like this


Solution

  • Android Time Picker Does Not Provide setInterval() method to do that we need to work with MaterialDateTimepicker

    implementation 'com.wdullaer:materialdatetimepicker:3.6.3'
    

    its latest version was conflicting with some of my libraries that's why i used 3.6.3

    Also those who are using NumberPicker to do that it doesn't work for me

    Calendar now = Calendar.getInstance();
                TimePickerDialog timePickerDialog = TimePickerDialog.newInstance(mTimePickerListener,
                        now.get(Calendar.HOUR_OF_DAY),
                        now.get(Calendar.MINUTE),
                        false
                );
                timePickerDialog.setThemeDark(false);
                timePickerDialog.setTitle("TimePicker Title");
                timePickerDialog.setTimeInterval(1, 15, 30); // 15 Minutes Interval
              //timePickerDialog.setTimeInterval(1, 30, 60); // 30 Minutes Interval
                timePickerDialog.setAccentColor(Color.parseColor("#9C27B0"));
                timePickerDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
                    @Override
                    public void onCancel(DialogInterface dialogInterface) {
                        Log.d("TimePicker", "Dialog was cancelled");
                    }
                });
                timePickerDialog.show(getFragmentManager(), "Timepickerdialog");
    

    }

     private TimePickerDialog.OnTimeSetListener mTimePickerListener = new TimePickerDialog.OnTimeSetListener() {
    
            @Override
            public void onTimeSet(TimePickerDialog view, int hourOfDay, int minute, int second) {
    
            }
        };