YouTubePlayerFragment inside ReyclerView

后端 未结 1 1152
Happy的楠姐
Happy的楠姐 2020-12-29 10:37

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

1条回答
  •  伪装坚强ぢ
    2020-12-29 11:15

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

    0 讨论(0)
提交回复
热议问题