android.app.DatePickerDialogを初めて使ったんですけどonDateSetが2回発生する事象にあったのでメモ
Calendar date = Calendar.getInstance();
DatePickerDialog dialog = new DatePickerDialog(this, new OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
Log.d("hoge", "onDateSet");
}
}, date.get(Calendar.YEAR), date.get(Calendar.MONTH), date.get(Calendar.DAY_OF_MONTH));
dialog.show();
04-11 11:55:03.437: D/hoge(19662): onDateSet
04-11 11:55:03.447: D/hoge(19662): onDateSet
対応
Calendar date = Calendar.getInstance();
DatePickerDialog dialog = new DatePickerDialog(this, new OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
if (!view.isShown()) {
return;
}
Log.d("hoge", "onDateSet");
}
}, date.get(Calendar.YEAR), date.get(Calendar.MONTH), date.get(Calendar.DAY_OF_MONTH));
dialog.show();
04-11 12:00:57.835: D/hoge(20291): onDateSet
これでok。
ってホントにこれでいいの???
参考
http://stackoverflow.com/questions/12436073/datepicker-ondatechangedlistener-called-twice