免责声明:标题应该足够清楚,这不是DatePicker
被解雇两次的问题,而是被解雇以前的值。
我不知道这怎么可能......
片段onCreateView
中的相关代码:
Log.d("PaginationFragment#", "setting the dateDepartureInit to : " + dateDepartureInit.get(Calendar.YEAR));
dateDeparture.init(dateDepartureInit.get(Calendar.YEAR), dateDepartureInit.get(Calendar.MONTH), dateDepartureInit.get(Calendar.DATE), new DatePicker.OnDateChangedListener() {
@Override
public void onDateChanged(DatePicker datePicker, int i, int i2, int i3) {
Calendar c = Calendar.getInstance();
c.set(i, i2, i3);
Log.d("PaginationFragment#", "onFormDateEvent : " + c.get(Calendar.YEAR));
listener.onFormDateEvent(CriterionName.DATE_DEPARTURE, c, iPosition);
}
});
输出:
03-04 .. 11909-11909/...app D/PaginationFragment#﹕ setting the dateDepartureInit to : 2016
03-04 .. 11909-11909/...app D/PaginationFragment#﹕ onFormDateEvent : 2015
正如您在日志中看到的那样,用于初始化DatePicker
的日期(在 2016 中),
然后事件触发,但使用之前的值( 2015 )。
请务必注意:
dateDepartureInit
的类型为Calendar
。ViewPager
编辑:
记录更多,我可以看到在onCreateView
完成后触发了更改日期的事件。
03-05 11:03:05.384 3003-3003/org.intracode.shoppingalertsystem.app D/PaginationFragment#﹕ start of onCreateView
03-05 11:03:05.390 3003-3003/org.intracode.shoppingalertsystem.app D/PaginationFragment#﹕ end of onCreateView
03-05 11:03:05.394 3003-3003/org.intracode.shoppingalertsystem.app
D/PaginationFragment#﹕ onDateChanged fired!