首页 > 代码库 > 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();
參考:https://code.google.com/p/android/issues/detail?id=64895
android 两次调用DatePickerDialog.onDateSet()
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。