此问题在android4.0以上存在,android2.3中没有
源码中,点击确定和取消按钮时,会出发onTimeSet;在dialog的onStop(比如dialog dismiss时)中,也调用了onTimeSet方法。
解决办法:
Calendar c = Calendar.getInstance();
c.add(Calendar.DAY_OF_YEAR, 1);
final DatePickerDialog dateDialog = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {
boolean fired = false;
public void onDateSet(final DatePicker view, final int year, final int monthOfYear, final int dayOfMonth) {
Log.i("PEW PEW", "Double fire check");
if (fired == true) {
Log.i("PEW PEW", "Double fire occured. Silently-ish returning");
fired = false;
return;
} else {
//first time fired
fired = true;
}
//Normal date picking logic goes here
}
}, c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH));
dateDialog.show();