我想将fragment
添加到recyclerView
的每个项目中
这是我的adapter
:
@NonNull
@Override
public ViewH onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_widget_recyclerview, parent, false);
return new ViewH(view);
}
@Override
public void onBindViewHolder(@NonNull ViewH holder, int position) {
WidgetSavedPaymentsFragment fragment = new WidgetSavedPaymentsFragment();
fragmentManager.beginTransaction().add(holder.mFrameLayoutFragmentContainer.getId(),fragment).commit();
}
@Override
public int getItemCount() {
return mWidgets.size();
}
@Override
public int getItemViewType(int position) {
return super.getItemViewType(position);
}
public class ViewH extends RecyclerView.ViewHolder{
@BindView(R.id.fragment_container)
FrameLayout mFrameLayoutFragmentContainer;
public ViewH(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
}
}
答案 0 :(得分:0)
使用holder.mFrameLayoutFragmentContainer更改R.id.fragment_container