I have a RecyclerView with CardViews inside it. I want each CardView to have its own YouTubePlayerFragment. Even if they can\'t all be active at once, I can\'t even seem to
So I figured it out. As long as you set a unique id for the YouTube FrameLayout, the activity will correctly insert the fragment on the right card! You can setId() on a View at runtime so just make sure they are somehow unique from one another.
// Add the YouTube fragment to view
wallpaperInfo.youTubePlayerFragment = YouTubePlayerFragment.newInstance();
// Must set a unique id to the framelayout holding the fragment or else it's always added to the first item in the recyclerView (the first card)
videoViewHolder.containerYouTubePlayer.setId(wallpaperInfo.id);
((Activity) activityContext).getFragmentManager().beginTransaction().add(videoViewHolder.containerYouTubePlayer.getId(), wallpaperInfo.youTubePlayerFragment).addToBackStack(null).commit();