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

后端 未结 12 1837
鱼传尺愫
鱼传尺愫 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条回答
  •  猫巷女王i
    2020-12-03 07:49

    public void showDatePicker() {
    
            final Calendar c = Calendar.getInstance();
            int year = c.get(Calendar.YEAR);
            int month = c.get(Calendar.MONTH);
            int day = c.get(Calendar.DAY_OF_MONTH);
    
            DatePickerDialog datePicker = new DatePickerDialog(getActivity(), (view, year1, month1, day1) -> {
                Calendar c1 = Calendar.getInstance();
                c1.set(year1, month1, day1);
                Date date = c1.getTime();
                SimpleDateFormat formatter = new SimpleDateFormat("dd MMMM yyyy");
                String d = formatter.format(date);
    //            btnDatePicker.setText(d);
    //            selectedDate = d;
            }, year, month, day) {
                @Override
                public void onClick(@NonNull DialogInterface dialog, int which) {
                    super.onClick(dialog, which);
                    if (which == DialogInterface.BUTTON_POSITIVE) {
                    } else if (which == DialogInterface.BUTTON_POSITIVE) {
    
                    }
                }
            };
    
            datePicker.getDatePicker().setMinDate(System.currentTimeMillis());
            datePicker.show();
        }
    

提交回复
热议问题