Search code examples
androidandroid-recyclerviewadapter

How to add dynamic view inside a recycler view row


I have one recycler view and inside each row I have one linear layout in which I have to insert some views dynamically according to data on each row.

I have tried

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

Can anyone tell me if I am doing anything wrong and suggest me the better approach?


Solution

  • try holder.dynamicLinearLayout.removeAllViews() before for loop