views:

176

answers:

2

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 on clicking date picker cancel button but dont see cancel event inside datepickerdialog

can any one guide me how to achieve this.

any help would be appreciated.

A: 

try this

 if (resultCode == RESULT_CANCELED) {
     Toast toast = Toast.makeText(this,"Datepicker Cancled", 10000);
     toast.show();
     return;
     }
Srikanth Naidu
in which event should i use it?
UMMA
you will be firing an Datepicker activity on Click, so on the public void onActivityResult() event u can call this code public void onActivityResult() { if (resultCode == RESULT_CANCELED) { Toast toast = Toast.makeText(this,"Datepicker Cancled", 10000); toast.show(); return; } }
Srikanth Naidu
+1  A: 

In this part of the code:

 private DatePickerDialog.OnDateSetListener mDateSetListener =
            new DatePickerDialog.OnDateSetListener() {

                public void onDateSet(DatePicker view, int year, 
                                      int monthOfYear, int dayOfMonth) {
                    mYear = year;
                    mMonth = monthOfYear;
                    mDay = dayOfMonth;
                    updateDisplay();
                }
            };

you have to implement also onClick():

public void  onClick  (DialogInterface  dialog, int which) {
   if (which == Button.NEGATIVE) {
      //Cancel
   }
}

API for Button.NEGATIVE

Roflcoptr
both are not working
UMMA
it never calls onClick event.
UMMA