I have an activity which has 2 or 3 fragments in one of those fragments i want to show Youtube video inside a recycler view what i have tried is
1.
when i try to access YouTubePlayerFragment which is in recyclerview item layout i got this error
"Type parameter T has incompatible upper bounds: View YouTubePlayerFragment"
public static class MyVideoViewHolder extends RecyclerView.ViewHolder{
YouTubePlayerFragment youTubePlayerFragment;
public MyVideoViewHolder(View itemView) {
super(itemView);
youTubePlayerFragment=itemView.findViewById(R.id.youtube_player_fragment);
}
}
i can't access fragment with findViewById and not able to get context here i don't how to call findFragmentById here if it will work.
2.
another solution i tried is using a frameLayout inside recyclerview item layout and then replace the fragment inside that framelayout but that is also not working i am getting
"No view found for id 0x7f070096 for fragment YouTubePlayerFragment"
public void onBindViewHolder(@NonNull MyVideoViewHolder holder, final int position) {
YouTubePlayerFragment youTubePlayerFragment=YouTubePlayerFragment.newInstance();
((Activity)mContext).getFragmentManager().beginTransaction().replace(holder.youtubePlayerFrameLayout.getId(),youTubePlayerFragment).commit();
youTubePlayerFragment.initialize(YoutubePlayerConfig.API_KEY, new YouTubePlayer.OnInitializedListener() {
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) {
youTubePlayer.cueVideo(videoListDataArrayList.get(position));
}
@Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
Log.d(TAG,"initilization fail");
}
});