我有一个包含Recylerview的Viewpager,它有2个不同的持有者。其中一个也是查看寻呼机。因此我嵌套了viewpager nad嵌套片段。当我点击第二个标签并点击第一个标签时,它很好。但是当我点击第三个标签并点击第一个标签时。它出现以下错误:
java.lang.IllegalArgumentException: No view found for id 0x7f0f00ce (:id/viewPagerComments) for fragment CommentFragment
viewPager.setAdapter(new MainViewPagerAdapter(getSupportFragmentManager(),models.size()));
navigationTabBar.setModels(models);
navigationTabBar.setViewPager(viewPager, 0);
private int size;
public MainViewPagerAdapter(FragmentManager fm, int size) {
super(fm);
this.size = size;
}
@Override
public Fragment getItem(int position) {
switch (position) {
case 0:
return DashboardtFragment.newInstance(size, position);
default:
return TempFragment.newInstance(size, position);
}
}
public static DashboardtFragment newInstance(int size, int index) {
Bundle args = new Bundle();
args.putInt(ARG_I,index);
args.putInt(ARG_S,size);
DashboardtFragment fragment = new DashboardtFragment();
fragment.setArguments(args);
return fragment;
}
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
{
final View v = inflater.inflate(R.layout.dashboard_fragment, null);
return v;
}
@Override
public void showRecyleview(DashboardResponseModel model) {
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
DashboardRecyleViewAdapter adapter = new DashboardRecyleViewAdapter(getActivity(),getChildFragmentManager(),model);
recyclerView.setAdapter(adapter);
}
public static class ViewHolder1 extends RecyclerView.ViewHolder {
public ViewHolder1(View itemView) {
super(itemView);
viewPager = itemView.findViewById(R.id.viewPagerComments);
}
}
case 1 :
return new ViewHolder1( layoutInflater.inflate(R.layout.dashboard_comments, parent,
false));
case 1:
ViewHolder1 viewHolder1 = (ViewHolder1) holder;
viewPager.setAdapter(new CommentViewPagerAdapter(
childFragmentManager,
model.getCommentList().size(),
model.getCommentList()
));
break;
public CommentViewPagerAdapter(FragmentManager fm, int size,
List<CommentList> list) {
super(fm);
this.size = size;
this.list=list;
}
@Override
public Fragment getItem(int position) {
return CommentFragment.newInstance(size,position,list.get(position));
}
public static CommentFragment newInstance(int size, int index, CommentList
comment) {
Bundle args = new Bundle();
args.putString(ARG_C,new Gson().toJson(comment));
args.putInt(ARG_I,index);
args.putInt(ARG_S,size);
CommentFragment fragment = new CommentFragment();
fragment.setArguments(args);
return fragment;
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup
container, @Nullable Bundle savedInstanceState)
{
final View v = inflater.inflate(R.layout.comment_content, null);
}
答案 0 :(得分:0)
<div id="wrapper" class="@(isMobile ? "mobileView" : "")">
首先创建一个customviewpager,而不是添加上面的代码。使用storeAdapter而不是setAdapter。