0
我有一個recyclerview
這需要加載youtube
一個視頻下方的其他類似的列表,下面是代碼。我用這個youtube api
。Youtubeview與RecyclerView裝載
與下面的代碼是,只有最後一個視頻被加載的問題,傳遞的值是正確的,工作。列表中的其他視頻無法加載,並且屏幕上出現黑屏。
public class YoutubeAdapter extends RecyclerView.Adapter<YoutubeAdapter.MyViewHolder> {
private String developer_key = "My Developer Key";
private Context context;
private ArrayList<String> video_id;
private LayoutInflater inflater;
public YoutubeAdapter(Context context, ArrayList<String> video_id) {
inflater = LayoutInflater.from(context);
this.context = context;
this.video_id = video_id;
}
public class MyViewHolder extends RecyclerView.ViewHolder {
YouTubePlayerView youtubeView;
public MyViewHolder(View view) {
super(view);
youtubeView = (YouTubePlayerView) view.findViewById(R.id.youtubeView);
}
}
@Override
public YoutubeAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = inflater.inflate(R.layout.video_content,parent,false);
return new MyViewHolder(itemView);
}
@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
final String video_string = video_id.get(position);
holder.youtubeView.initialize(developer_key, new YouTubePlayer.OnInitializedListener() {
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) {
if (!b) {
youTubePlayer.cueVideo(video_string);
}
}
@Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
Toast.makeText(context, "Failed to load video", Toast.LENGTH_SHORT).show();
}
});
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public int getItemCount() {
return video_id.size();
}
}
你的意思'YouTube的videos'的縮略圖沒有加載? –
我只使用我的YouTube視圖,而不是thumbnailview ..會發生什麼,只有最後一個帶有按鈕的視頻是可見的,可以播放.. –
是你的'適配器'包含所有數據你檢查它是'數組列表'大小? –