My app uses a DatePicker
. When I open the DatePicker
and click on Done
the date gets choosen. The problem is, that the date also gets choosen, if the user clicks besides the DatePicker
. See here:
The Listener
should only react if the Done Button
is clicked. But it also reacts if the surrounding (red) of the DatePicker
is clicked.
My Question:
How do I prevent this?
If you want to see some code, pls leave a comment.
I already tried this: How to handle date picker dialog not to set in edittext when clicked outside of dialog android?
Calendar c = Calendar.getInstance();
mYear = c.get(Calendar.YEAR);
mMonth = c.get(Calendar.MONTH);
mDay = c.get(Calendar.DAY_OF_MONTH);
//DatePickerDialog mDatePicker;
DatePickerDialog mDatePicker;
mDatePicker = new DatePickerDialog(this, AlertDialog.THEME_DEVICE_DEFAULT_LIGHT, new DatePickerDialog.OnDateSetListener() {
private boolean fired;
public void resetFired(){
fired = false;
}
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
if(view.isShown()){
if(fired){
setDate(year, monthOfYear, dayOfMonth);
//ListView erneuern
adapter.notifyDataSetChanged();
return;
}
fired = true;
}
}
}, mYear, mMonth, mDay);
mDatePicker.setCanceledOnTouchOutside(true);
mDatePicker.setTitle("Wähle ein Datum");
mDatePicker.show();
But it does not work correctly. The click on the background bug gets solved. But now the Done Button
stops working.