如何将片段添加到recyclerView项目

时间:2018-08-10 06:58:27

标签: android android-recyclerview

我想将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);
    }
}

1 个答案:

答案 0 :(得分:0)

使用holder.mFrameLayoutFragmentContainer更改R.id.fragment_container