TimePickerDialog cancel button

前端 未结 6 1169
暗喜
暗喜 2021-01-06 07:30

I have an activity - TimePickerActivity - which creates a TimePickerDialog. I have a onTimeSetListener which responds to the Set button at the end of which it calls finish(

6条回答
  •  醉梦人生
    2021-01-06 07:59

    TimePickerDialog.OnTimeSetListener timePickerListener = new TimePickerDialog.OnTimeSetListener() {
        @Override
        public void onTimeSet(TimePicker view, int hour, int minute) {
                //ok button clicked 
        }
    };
    
    Calendar c = Calendar.getInstance();
    int now_hour = c.get(Calendar.HOUR_OF_DAY);
    int now_minutes = c.get(Calendar.MINUTE);
    
    final TimePickerDialog timePickerDialog = new TimePickerDialog(this, timePickerListener, now_hour, now_minutes + 1, false);
    
    timePickerDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            //cancel button clicked
        }
    });
    
    timePickerDialog.show();
    

提交回复
热议问题