我在DatePicker
内Fragment
内有ViewPager
。
evertime我做了一个改变,我看到事件发生了两次。
这是常见的吗?这是我的代码:
public class CreateWishFormDatePaginationFragment extends Fragment implements DatePicker.OnDateChangedListener {
public static CreateWishFormDatePaginationFragment newInstance(int position) {
Log.i("PaginationFragment#", " CreateWishFormDatePaginationFragment called for fragment : " + position);
CreateWishFormDatePaginationFragment fragment = new CreateWishFormDatePaginationFragment();
Bundle args = new Bundle();
args.putInt(KEY_POSITION, position);
fragment.setArguments(args);
return fragment;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// ... (omitted)
dateDeparture.init(dateDepartureInit.get(Calendar.YEAR), dateDepartureInit.get(Calendar.MONTH), dateDepartureInit.get(Calendar.DATE), this);
}
@Override
public void onDateChanged(DatePicker datePicker, int i, int i2, int i3) {
if (datePicker.isShown()) {
Calendar c = Calendar.getInstance();
c.set(i, i2, i3);
Log.d("PaginationFragment#", "onDateChanged: " + c.get(Calendar.YEAR));
listener.onFormDateEvent(CriterionName.DATE_DEPARTURE, c, iPosition);
txtDepartureWeekday.setText(c.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.ENGLISH));
}
}
}
日志:
03-04 15:13:01.238 28352-28352/org.intracode.shoppingalertsystem.app D/PaginationFragment#﹕ onDateChanged: 2016
...
03-04 15:13:01.241 28352-28352/org.intracode.shoppingalertsystem.app D/PaginationFragment#﹕ onDateChanged: 2016
任何其他控件都不会发射两次。