How do I detect a cancel click of the datepicker dialog?

后端 未结 12 1844
鱼传尺愫
鱼传尺愫 2020-12-03 06:51

i am using following example of date picker

http://developer.android.com/guide/tutorials/views/hello-datepicker.html

now i want to perform some functionality

12条回答
  •  余生分开走
    2020-12-03 07:35

    DatePickerDialog now exposes a onCancel listener.

    DatePickerDialog datePickerDialog = DatePickerDialog.newInstance(new DatePickerDialog.OnDateSetListener() {
            @Override
            public void onDateSet(DatePickerDialog datePickerDialog, int year, int month, int day) {
                // Do whatever you want when the date is selected.
                editText.setText(String.format("%04d-%02d-%02d", year, month+1, day));
            }
        }, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),calendar.get(Calendar.DAY_OF_MONTH));
    
        datePickerDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
    
            }
        });
    

提交回复
热议问题