gpt4 book ai didi

android - 我可以在另一个类/Activity 中使用 ItemCount() 方法值吗?

转载 作者:行者123 更新时间:2023-11-29 22:44:06 25 4
gpt4 key购买 nike

recyclerView 的 ItemCount 方法是:

@Override
public int getItemCount() {
Log.e("Notification Size is " ,String.valueOf(slideshowModelList.size()));

return slideshowModelList.size();
}

LogOutput 是:8

这是我完整的适配器类代码:

public class SlideShowAdapter extends RecyclerView.Adapter<SlideShowAdapter.ViewHolder> {

Context context;
List<SlideshowModel> slideshowModelList;

public SlideShowAdapter(Context context, List<SlideshowModel> slideshowModelList) {
this.context = context;
this.slideshowModelList = slideshowModelList;
}

@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.custom_layout_notifications,
parent, false);
ViewHolder viewHolder = new ViewHolder(view);
return viewHolder;
}

@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
SlideshowModel slideshowModel = slideshowModelList.get(position);
Picasso.get().load(slideshowModel.getImage()).fit().centerCrop().placeholder(R.drawable.placeholders).into(holder.image);
holder.title.setText(slideshowModel.getTitle());
holder.description.setText(slideshowModel.getDesc());
holder.date.setText(slideshowModel.getDate());

if (getItemCount() !=1){
holder.notif_icon.setVisibility(View.VISIBLE);
}
else{
holder.notif_icon.setVisibility(View.GONE);
}
}

@Override
public int getItemCount() {
Log.e("Notification Size is " ,String.valueOf(slideshowModelList.size()));

return slideshowModelList.size();
}

class ViewHolder extends RecyclerView.ViewHolder{
ImageView image,notif_icon;
TextView title,description,date;

public ViewHolder(@NonNull View itemView) {
super(itemView);

image= itemView.findViewById(R.id.imagecontent);
title = itemView.findViewById(R.id.title);
description = itemView.findViewById(R.id.desc);
date= itemView.findViewById(R.id.date);
notif_icon= itemView.findViewById(R.id.notif_icon);

}
}
}

我可以在另一个与 recyclerView 的父类无关的类/Activity 中使用这个 getItemCount() 值吗?

EDIT : In my MainActivity , the value received is :

E/Notification Size is: 0

Whereas In my RecyclerView Activity i am getting value as : E/Notification Size is: 2

最佳答案

试试这个

SlideShowAdapter  adpater=new SlideShowAdapter(context,list);
int count=adapter.getItemCount();

关于android - 我可以在另一个类/Activity 中使用 ItemCount() 方法值吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58706505/

25 4 0
文章推荐: mysql - 如何修复查询间隔中的语法错误?
文章推荐: php - 分解数据库值,然后通过选择