How to add fragment to recyclerView item

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



How to add fragment to recyclerView item



I want to add fragment to each item of my recyclerView
Here is my adapter:


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);






Where is my mistake..Can somebody help me?
– Mr Java
Aug 10 at 6:59





Please, don't add your code as an image but as text, with the proper markdown formatting. It will be much more helpful to whoever wants to answer
– user2340612
Aug 10 at 7:02





Possible duplicate of how to start fragment from adapter class
– sourabh kaushik
Aug 10 at 7:35





take a look at this it will solve this stackoverflow.com/a/45934924/9857545
– sourabh kaushik
Aug 10 at 7:36





I tried but again the same error
– Mr Java
Aug 10 at 8:42




1 Answer
1



change R.id.fragment_container with holder.mFrameLayoutFragmentContainer





please mark it as answered if this solves your problem
– user9857545
Aug 10 at 7:05





I can't use holder.mFrameLayoutFragmentContainer.Here I needed id I think
– Mr Java
Aug 10 at 7:14






((FragmentActivity) view.getContext()).getFragmentManager().beginTransaction().replace(R.id.fragment_container,fragment).commit();
– user9857545
Aug 10 at 7:21





try this it might help
– user9857545
Aug 10 at 7:21





((FragmentActivity) view.getContext()). what is view here?
– Mr Java
Aug 10 at 7:28






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard