如何在回收站视图行中添加动态视图
How to add dynamic view inside a recycler view row
我有一个回收站视图,在每一行中我有一个线性布局,我必须在其中根据每一行的数据动态插入一些视图。
我试过了
for(int i=0;i<4;i++){
View view = LayoutInflater.from(context).inflate(R.layout.sales_total_item_with_img,null);
holder.dynamicLinearLayout.addView(view);
}
the above code is written inside onBindHolder method and working but it is inflating each time I scroll and this thing is just adding more and more views
任何人都可以告诉我我做错了什么并建议我更好的方法吗?
在 for 循环之前尝试 holder.dynamicLinearLayout.removeAllViews()
我知道回复晚了,但仍然只想分享 Kotlin 的代码。在 BindViewHolder 中就这样做。
holder.llDescription.removeAllViews()
for (i in 0 until data.description.size) {
val childView: View = context.layoutInflater.inflate(R.layout.product_description, null)
val tvDescription : TextView = childView.findViewById(R.id.tvDescription)
tvDescription.text = data.description[i].title
holder.llDescription.addView(childView)
}
我有一个回收站视图,在每一行中我有一个线性布局,我必须在其中根据每一行的数据动态插入一些视图。
我试过了
for(int i=0;i<4;i++){ View view = LayoutInflater.from(context).inflate(R.layout.sales_total_item_with_img,null); holder.dynamicLinearLayout.addView(view); }
the above code is written inside onBindHolder method and working but it is inflating each time I scroll and this thing is just adding more and more views
任何人都可以告诉我我做错了什么并建议我更好的方法吗?
在 for 循环之前尝试 holder.dynamicLinearLayout.removeAllViews()
我知道回复晚了,但仍然只想分享 Kotlin 的代码。在 BindViewHolder 中就这样做。
holder.llDescription.removeAllViews()
for (i in 0 until data.description.size) {
val childView: View = context.layoutInflater.inflate(R.layout.product_description, null)
val tvDescription : TextView = childView.findViewById(R.id.tvDescription)
tvDescription.text = data.description[i].title
holder.llDescription.addView(childView)
}