gpt4 book ai didi

android - 如何获取 RecyclerView 项目计数?

转载 作者:行者123 更新时间:2023-12-05 00:10:32 26 4
gpt4 key购买 nike

嘿,我有 回收站查看列表 像第 1 集,第 2 集,第 3 集,...如何计算总项目并设置为 TextView ,如当前 episode = episode(total items)
这是我的适配器

public class EpisodeAdapter  extends  RecyclerView.Adapter<EpisodeAdapter.EpisodeHolder>{
private List<Episode> episodeList;
public EpisodeAdapter(List<Episode> episodeList) {
this.episodeList = episodeList;
}
@Override
public EpisodeHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_episode , null);
EpisodeAdapter.EpisodeHolder mh = new EpisodeAdapter.EpisodeHolder(v);
return mh;
}
@Override
public void onBindViewHolder(EpisodeHolder holder, final int position) {
if (episodeList.get(position).getImage()!=null){
Picasso.with(SerieActivity.this).load(episodeList.get(position).getImage()).into(holder.image_view_item_episode_thumbail);
}else{
Picasso.with(SerieActivity.this).load(poster.getImage()).into(holder.image_view_item_episode_thumbail);
}
holder.text_view_item_episode_title.setText(episodeList.get(position).getTitle());
if (episodeList.get(position).getDuration() != null){
holder.text_view_item_episode_duration.setText(episodeList.get(position).getDuration());
}
}

最佳答案

从 recyclerView 中集合的适配器获取总项目数。

recyclerView&adapter不能为null,否则可以查到total
项目。

recyclerView.getAdapter().getItemCount();

关于android - 如何获取 RecyclerView 项目计数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60162270/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com