Avoid DatePickerDialog calls onDateSet two times


While working with DatePickerDialog, I see an issue when setting a date and click done button. Its calling onDateSet method two times.


here is a simple solution for it. DatePicker parameter object has a method called isShown(). Place method statements in the if condition of isShown(), which avoids calling onDateSet method statements two times.

public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
    if(view.isShown()) {
      //method statements 
       Log.i(MyClassName.class.getName(), year+ "/" +      monthOfYear   + "/" + dayOfMonth); 

ref & credits to link.

Cheers.. 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *