我想在服务器的回收器视图中添加用于动态响应的序列号。我要做的是建议我。
Context context;
List<Ordere> orderes;
public MyRewardsAdapter(Context context, List<Ordere> orderes) {
this.context = context;
this.orderes = orderes;
}
@Override
public MyRewardsViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.reward_list_items,null);
MyRewardsViewHolder myRewardsViewHolder = new MyRewardsViewHolder(context, view);
return myRewardsViewHolder;
}
@Override
public void onBindViewHolder(MyRewardsViewHolder holder, int position) {
holder.txtRewardid.setText(orderes.get(position).getOrderid());
holder.txtrewardpoint.setText(orderes.get(position).getTotal_point());
holder.txtRewardDate.setText(orderes.get(position).getDate());
}
@Override
public int getItemCount() {
return orderes.size();
}
答案 0 :(得分:2)
如果要显示从0开始的序列号,可以直接使用viewholder.getAdapterPosition()
。如果要从1开始,只需将其添加viewholder.getAdapterPosition()+1
,然后再在任何文本视图中进行设置即可。