我想在 ViewPager 内的片段中设置一些 TextView。我在实例化页面时将我的 TextViews 设置在我的片段的 onActivityCreated 函数中。根据在 getItemPosition 中返回POSITION_NONE的一些帖子解决了我的问题,但是因为每次删除所有视图都不是一种有效的方法。所以我将其更改为instatiateItem(ViewGroup container, int position)但是当我返回我的 Fragments 的视图时它会抛出:
ClassCastException : android.Widget.LinearLayout cannot be cast to android.support.v4.app.Fragment
这是我的 instantiateItem(ViewGroup container, int position) 函数,有人知道我该如何管理这个异常吗?或者如何刷新 ViewPager 内的 Fragment 中的 TextView?提前致谢
@Override
public Object instantiateItem(ViewGroup container, int position)
{
LayoutInflater inflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (position == 3) {
view = inflater.inflate(R.layout.projecttracking_detail_customerproject_fragment, null);
((ViewPager) container).addView(view, 0);
}
else if(position == 2) {
view = inflater.inflate(R.layout.projecttracking_detail_projectinformation_fragment, null);
((ViewPager) container).addView(view, 0);
}
return view;
}