YouTubePlayerFragment inside ReyclerView

喜夏-厌秋 提交于 2019-11-25 15:19:04

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();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!