title: When replacing fragment inside a RecyclerView item : "No view found for id" of container
body: <p>I'm having trouble referencing the Container "youtube_fragmento" inside the ViewHolders</p>
  
  <p>My idea is to make a RecyclerView with viewHolders that switches between YoutubePlayerFragment and a PreviewFragment(by changing the fragment inside a container) , 
  activating only the YoutubeVideoPlayerFragment of the video clicked</p>
  
  <p>Fragment where is put the RecyclerView :</p>
  
  <pre><code>    public class CanalesFragment extends Fragment {
  
  private static final String ARG_PARAM1 = "1";
  private static final String ARG_PARAM2 = "2";
  ListView lvVideo;
  String searchName;
  String TAG="ChannelActivity";
  String URL="https://www.googleapis.com/youtube/v3/search?part=snippet&amp;channelId=UC9CYT9gSNLevX5ey2_6CK0Q&amp;maxResults=25&amp;key="+YoutubeConfig.getApiKey();
  
  private String mParam1;
  private String mParam2;
  private static CanalesRecyclerAdapter canalesRecyclerAdapter;
  public static ArrayList&lt;video&gt; videos;
  
  private OnFragmentInteractionListener mListener;
  
  public CanalesFragment() {
      // Required empty public constructor
  }
  
  public static CanalesFragment newInstance(String param1, String param2) {
      CanalesFragment fragment = new CanalesFragment();
      Bundle args = new Bundle();
      args.putString(ARG_PARAM2, param2);
      fragment.setArguments(args);
      return fragment;
  }
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      if (getArguments() != null) {
          mParam1 = getArguments().getString(ARG_PARAM1);
          mParam2 = getArguments().getString(ARG_PARAM2);
  
      }
  
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      // Inflate the layout for this fragment
      View v = inflater.inflate(R.layout.fragment_canales, container, false);
  
      videos = new ArrayList&lt;video&gt;();
      videoParser.getVideosFromUrl(URL);
  
   RecyclerView recyclerView = v.findViewById(R.id.recyclerViewCanales);
   canalesRecyclerAdapter = new CanalesRecyclerAdapter(getContext(),getActivity(), 
   this.getChildFragmentManager(),videos);
  
   canalesRecyclerAdapter.setOnItemClickListener(new 
  CanalesRecyclerAdapter.OnItemClickListener() {
  @Override
  public void onItemClick(FrameLayout b, View view, video obj, int position) 
  {//custom made method to input a ClickListener to the adapter
      for (int i = 0; i &lt; videos.size(); i++) { //when one video is clicked i set them all to PreviewFragment
          videos.get(i).reproduciendo=false;
      }
      canalesRecyclerAdapter.notifyDataSetChanged();
      videos.get(position).reproduciendo=true;   //then change to 
  YoutubePlayerFragment at the one clicked
      canalesRecyclerAdapter.notifyItemChanged(position);
  }
  });
  recyclerView.setAdapter(canalesRecyclerAdapter);
  
  
      recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
      return v;
  
  
  }
  
  // TODO: Rename method, update argument and hook method into UI event
  public void onButtonPressed(Uri uri) {
      if (mListener != null) {
          mListener.onFragmentInteraction(uri);
      }
  }
  
  @Override
  public void onAttach(Context context) {
      super.onAttach(context);
      if (context instanceof OnFragmentInteractionListener) {
          mListener = (OnFragmentInteractionListener) context;
      } else {
          throw new RuntimeException(context.toString()
                  + " must implement OnFragmentInteractionListener");
      }
  }
  
  @Override
  public void onDetach() {
      super.onDetach();
      mListener = null;
  }
  
  public static void updateRecyclerView(){
      canalesRecyclerAdapter.notifyDataSetChanged();
  
  }
  public interface OnFragmentInteractionListener {
      // TODO: Update argument type and name
      void onFragmentInteraction(Uri uri);
  }
  }
  </code></pre>
  
  <p>this is the RecyclerAdapter :</p>
  
  <pre><code>public class CanalesRecyclerAdapter extends 
  RecyclerView.Adapter&lt;RecyclerView.ViewHolder&gt; {
  
  
  @NonNull
  Context context;
  Activity activity;
  private OnItemClickListener mOnItemClickListener;
  ArrayList&lt;video&gt; videos;
  private StorageReference mStorageRef;
  private FragmentManager childFragmentManager;
  final private int HACK_ID_PREFIX = 12345678; //preset number to generate IDs
  
  public CanalesRecyclerAdapter(Context context, Activity activity, 
  FragmentManager childFragmentManager, ArrayList&lt;video&gt; videos) {
      this.context = context;
      this.videos = videos;
      this.activity=activity;
      this.childFragmentManager = childFragmentManager;
      this.mStorageRef = FirebaseStorage.getInstance().getReference();
  }
  public interface OnItemClickListener {
      void onItemClick(FrameLayout b , View view, video obj, int position);
  
  }
  
  public void setOnItemClickListener(final OnItemClickListener mItemClickListener) {
      this.mOnItemClickListener = mItemClickListener;
  }
  
  @Override
  public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
  
  
      LayoutInflater inflater = (LayoutInflater) 
  context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      View row = inflater.inflate(R.layout.itemyoutube, viewGroup, false);
      videoItem item = new videoItem(row,context,videos);
  
  
      return item;
  
  
  
  }
  
  @Override
  public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder viewHolder, final int i) {
  
      bindVideo((videoItem)viewHolder, i);
  
      final video s = videos.get(i);
      if(videos.get(i).reproduciendo){ //if this video is the one that should play
  
          YouTubePlayerSupportFragment youTubePlayerFragment = YouTubePlayerSupportFragment.newInstance();
          FragmentTransaction transaction = childFragmentManager.beginTransaction();
          transaction.replace(HACK_ID_PREFIX+i,  youTubePlayerFragment).commit();
  
          YouTubePlayer.OnInitializedListener OIL = new YouTubePlayer.OnInitializedListener() {
              @Override
              public void onInitializationSuccess(YouTubePlayer.Provider provider, final YouTubePlayer youTubePlayer, boolean b) {
                  youTubePlayer.loadVideo(videos.get(i).videoID);
                  youTubePlayer.setShowFullscreenButton(false);
                  youTubePlayer.setPlaybackEventListener(new YouTubePlayer.PlaybackEventListener() {
                      @Override
                      public void onPlaying() {
  
                          youTubePlayer.seekToMillis(0);
  
                      }
  
                      @Override
                      public void onPaused() {
  
                      }
  
                      @Override
                      public void onStopped() {
  
                      }
  
                      @Override
                      public void onBuffering(boolean b) {
  
                      }
  
                      @Override
                      public void onSeekTo(int i) {
  
                      }
                  });
  
  
              }
  
              @Override
              public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
  
              }
          };
          youTubePlayerFragment.initialize(YoutubeConfig.getApiKey(), OIL);
  
      }else{ //if its not playing we replace container with a Preview
  
          FragmentTransaction transaction = childFragmentManager.beginTransaction();
           videoPreviewFragment frag = videoPreviewFragment.newInstance(videos.get(i).videoID,"");
  
  
          transaction.replace(HACK_ID_PREFIX+i,frag).commit();
  
  
      }
  
      ((videoItem) viewHolder).youtubeVideo.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              if (mOnItemClickListener != null) { 
                  mOnItemClickListener.onItemClick(((videoItem) viewHolder).youtubeVideo,v, s, i);
              }
          }
      });
  
  
             }
  
  private void bindVideo(final videoItem viewHolder, int i) { //para darle un tag al momento de asignar el video
      View view = viewHolder.itemView.findViewWithTag("video_container");
      if (view != null) {
  
          Log.e("idGenerado", String.valueOf(HACK_ID_PREFIX+i));
          view.setId(HACK_ID_PREFIX + i);
      }
  }
  @Override
  public int getItemCount() {
  
      return videos.size();
  }
  
  }
  
  class videoItem extends RecyclerView.ViewHolder{
  FrameLayout  youtubeVideo;
  ArrayList&lt;video&gt; videos = new ArrayList&lt;video&gt;();
  Context context;
  
  public videoItem(View itemView, Context context, ArrayList&lt;video&gt; videos) {
      super(itemView);
      this.videos = videos;
      this.context = context;
  
      youtubeVideo = itemView.findViewById(R.id.youtube_fragmento);
  
  }}
  </code></pre>
  
  <p>The layout from item_youtube , inflated for a viewHolder :</p>
  
  <pre><code>&lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="260dp"
  android:background="#FFFFFF"
      android:id="@+id/youtube_fragmento"
      android:layout_centerHorizontal="true"
      android:tag="video_container"
      android:visibility="visible"
      app:layout_constraintEnd_toEndOf="parent"
      app:layout_constraintHorizontal_bias="0.532"
      app:layout_constraintStart_toStartOf="parent"
      app:layout_constraintTop_toTopOf="parent"&gt;
  
  &lt;/FrameLayout&gt;
  </code></pre>
  
  <p>When i put on a onBindViewHolder, with the code below, a fragment inside the container, it always replaces in the Container[R.id.youtube_fragmento] of the first RecyclerView item :</p>
  
  <pre><code> FragmentTransaction transaction = 
  getChildFragmentManager().beginTransaction();
    transaction.replace(R.id.youtube_fragmento, 
  youTubePlayerFragment).commit();
  </code></pre>
  
  <p>Apparently in this case its giving for container [R.id.youtube_fragmento] the same ID for every viewHolder,</p>
  
  <p>so i opted to give each container an own ID (with bindVideo() function) setting a custom ID to the container depending on the position</p>
  
  <p>It's working for the first 3 viewHolders(the ones that fit the first drawn screen) , but after scrolling to see more, i get this error, being the ID "0xbc6151" the ID set with bindVideo() to the 4th viewHolder container</p>
  
  <p>Error : " 
  Invalid ID 0x00bc6151.
   No view found for id 0xbc6151 (unknown) for fragment videoPreviewFragment{32586d8 #25 id=0xbc6151} "</p>
  
  <p>I also tried setting viewHolder.isRecyclable(false) to check if recycling is giving me problems with custom IDs and the problem is still there</p>