开发者社区> 问答> 正文

如何在RecyclerView的Adapter中设置ViewHolder的视图内容?

如何在RecyclerView的Adapter中设置ViewHolder的视图内容?

展开
收起
迪哒迪滴喵 2024-07-22 16:37:17 17 0
1 条回答
写回答
取消 提交回答
  • 在RecyclerView的Adapter中,通过重写onBindViewHolder方法来设置ViewHolder的视图内容。在这个方法中,你可以根据数据源(如List)中的元素来更新ViewHolder中的各个视图组件。例如:

    @Override 
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) { 
    GoodsModel model = dataList.get(position); 
    holder.title.setText(model.title); 
    holder.price.setText(String.format("%.2f", model.price / 100f)); 
    }
    
    2024-07-22 18:26:16
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载