8
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

DatePickerDialogのonDateSetが2回発生する

Posted at

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

8
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?