javaandroidtimepickerdialog

TimePickerDialog Constructor Issues


if (v == btnEndTimePicker) {

            final Calendar c = Calendar.getInstance() ;
            mHour = c.get(Calendar.HOUR_OF_DAY);
            mMinutes = c.get(Calendar.MINUTE);
            TimePickerDialog timePickerDialog = new TimePickerDialog(true, this,
                    (view, hour, minutes) -> {
                        return editStartTime.setText((hour + ":" + minutes), mHour, mMinutes);
                    });
            timePickerDialog.show();
        }
        if (v == btnStartTimePicker) {

            final Calendar c = Calendar.getInstance() ;
            sHour = c.get(Calendar.HOUR_OF_DAY);
            sMinutes = c.get(Calendar.MINUTE);
            CalendarDialog timePickerDialog = new CalendarDialog(true, this,
                    (view, hour, minutes) -> {
                        return editStartTime.setText((hour + ":" + minutes), sHour, sMinutes);
                    });
            timePickerDialog.show();
        }

I'm not sure what to do here, I used a similar code to pop up a Calendar Date Dialog and choose a date that is then dropped into an EditText field. When I do it for TimePickerDialog it says it it's expecting a char[] not a String.


Solution

  • You Give Wrong Parameters to TimePickerDialog object its get

         public TimePickerDialog (Context context,  
                TimePickerDialog.OnTimeSetListener listener, 
                int hourOfDay, 
                int minute, 
                boolean is24HourView)
    

    replace this

      TimePickerDialog timePickerDialog = new TimePickerDialog(true, this,
                    (view, hour, minutes) -> {
                        return editStartTime.setText((hour + ":" + minutes), mHour, mMinutes);
                    });
    

    with

    TimePickerDialog timePickerDialog = new TimePickerDialog(this,listener,2,25,true);
    

    these are right Parameters for more check it out

    https://developer.android.com/reference/android/app/TimePickerDialog