我正在使用以下方法更新我的片段 2:
@Override
public int getItemPosition(Object object) {
FragmentPage2 f = (FragmentPage2) object;
if (f != null) {
f.update();
}
return super.getItemPosition(object);
}
现在,当我在 中添加和附加和不同时Fragment
,getItem(int position)
一切似乎都运行良好。但是,当我运行mPager.getAdapter().notifyDataSetChanged();
它时,它会抛出我:
08-07 19:45:50.844: E/AndroidRuntime(17776): java.lang.ClassCastException: com.foodbuilder.FragmentPage1 cannot be cast to com.foodbuilder.FragmentPage2
08-07 19:45:50.844: E/AndroidRuntime(17776): at com.foodbuilder.MainActivity$MyAdapter.getItemPosition(MainActivity.java:967)
08-07 19:45:50.844: E/AndroidRuntime(17776): at android.support.v4.view.ViewPager.dataSetChanged(ViewPager.java:851)
08-07 19:45:50.844: E/AndroidRuntime(17776): at android.support.v4.view.ViewPager$PagerObserver.onChanged(ViewPager.java:2772)
08-07 19:45:50.844: E/AndroidRuntime(17776): at android.database.DataSetObservable.notifyChanged(DataSetObservable.java:37)
08-07 19:45:50.844: E/AndroidRuntime(17776): at android.support.v4.view.PagerAdapter.notifyDataSetChanged(PagerAdapter.java:276)
08-07 19:45:50.844: E/AndroidRuntime(17776): at com.foodbuilder.MainActivity.onDialogPositiveClick(MainActivity.java:888)
08-07 19:45:50.844: E/AndroidRuntime(17776): at com.foodbuilder.TablesDialogFragment$2.onClick(TablesDialogFragment.java:57)
08-07 19:45:50.844: E/AndroidRuntime(17776): at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:166)
`
怎么了?非常感谢。