Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 301
Vivek Pratap Singh Avatar asked Jan 06 '23 19:01

Vivek Pratap Singh


1 Answers

try holder.dynamicLinearLayout.removeAllViews() before for loop

like image 144
Ajit Avatar answered Feb 06 '23 04:02

Ajit