android 两次调用DatePickerDialog.onDateSet()

枕上诗书闲处好,门前风景雨来佳。这篇文章主要讲述android 两次调用DatePickerDialog.onDateSet()相关的知识,希望能为你提供帮助。
在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();







【android 两次调用DatePickerDialog.onDateSet()】參考:https://code.google.com/p/android/issues/detail?id=64895





    推荐阅读