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();



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

android 两次调用DatePickerDialog.onDateSet(),,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。