RecyclerView is duplicating items

I replicated your problem.

adding holder.priceGroup.removeAllViews(); on onBindViewHolder will fix it. Like so:

 @Override
public void onBindViewHolder(ChecklistAdapter.ViewHolder holder,
                             int position) {
    Checklist packageModel = packageList.get(position);
    holder.packageName.setText(packageModel.getTitle());

    int id = (position+1)*100;
    holder.priceGroup.removeAllViews();

    for(String price : packageModel.getQuestions()){
        RadioButton rb = new RadioButton(ChecklistAdapter.this.context);
        rb.setId(id++);
        rb.setText(price);
        holder.priceGroup.addView(rb);
    }
}

You were adding to the view every time without removing the previous views.


Use holder.setIsRecyclable(false) in onCreateViewHolder()

It worked for me.


you have to setHasStableIds(true) to your Adapter in your activity.

and in your Adapter class you have to set below method. It may help you. it is work for me.

  @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public int getItemViewType(int position) {
        return position;
    }


    @Override
    public void setHasStableIds(boolean hasStableIds) {
        super.setHasStableIds(hasStableIds);
    }

you want like this?

enter image description here