在4.2.2版本号上调用系统的DatePickerDialog,发现点击确定时系统调用onDateSet()两次,须要过滤当中的一次。

Calendar mCalendar = Calendar.getInstance();
mCalendar.add(Calendar.DAY_OF_YEAR, 1);
final DatePickerDialog dateDialog = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {
boolean mFired = false;
public void onDateSet(final DatePicker view, final int year, final int monthOfYear, final int dayOfMonth) {
Log.i("PEW PEW", "Double fire check");
if (mFired == true) {
Log.i("PEW PEW", "Double fire occured. Silently-ish returning");
return;
} else {
//first time mFired
mFired = true;
}
//Normal date picking logic goes here
}
}, mCalendar.get(Calendar.YEAR), mCalendar.get(Calendar.MONTH), mCalendar.get(Calendar.DAY_OF_MONTH));
dateDialog.show();

參考:https://code.google.com/p/android/issues/detail?id=64895

05-11 17:45