Why RecyclerView is adding the last CardView deleted?

So I have a RecyclerView that contains a CardView and I have a button in my Activity that at each click it adds a new card to the RecyclerView.

And in each card I have another button that when pressed, deletes the CardView being touched.

The problem is that I add new rows to the RecyclerView and I delete some then when I add rows again the new ones added are the old ones that I deleted before.

How can I fix this?

This is my Activity:

public class MainActivity extends AppCompatActivity {

    private ArrayList exercises;
    private Button btnNewExercise;
    private RecyclerView recyclerView;
    int i = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initViews();
    }

    private void initViews() {
        recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
        recyclerView.setHasFixedSize(true);
        RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getApplicationContext());
        recyclerView.setLayoutManager(layoutManager);
        exercises = new ArrayList<>();

        final RecyclerView.Adapter adapter = new RecyclerViewAdapter(exercises);
        recyclerView.setAdapter(adapter);

        btnNewExercise = (Button) findViewById(R.id.btnNewExercise);


        btnNewExercise.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                exercises.add("Test" +i);
                i++;

                adapter.notifyDataSetChanged();
                adapter.notifyItemInserted(exercises.size());
            }
        });


    }
}

And this is my adapter:

public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder> {

    private ArrayList<String> mDataset;


    public RecyclerViewAdapter(ArrayList myDataset) {
        mDataset = myDataset;
    }

    @Override
    public RecyclerViewAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.card_view_row, viewGroup, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(final RecyclerViewAdapter.ViewHolder viewHolder, int i) {
        viewHolder.tv_exercise.setText(mDataset.get(i));
    }

    @Override
    public int getItemCount() {
        return mDataset.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder{

        private TextView tv_exercise;
        private Button btnEliminarRow;

        public ViewHolder(View view) {
            super(view);
            tv_exercise = (TextView)view.findViewById(R.id.exercise_text);
            btnEliminarRow = (Button) view.findViewById(R.id.btnEliminarRow);
            final View posas = view;


            btnEliminarRow.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    removeAt(getAdapterPosition());
                }
            });
        }

        public void removeAt(int position) {
            mDataset.remove(position);
            notifyItemRemoved(position);
            notifyItemRangeChanged(position, mDataset.size());
        }
    }
}

Logs when adding 3 elements:

07-31 19:02:57.643 21770-21770/com.ravelinx.prueba I/System.out: Test0
07-31 19:02:58.070 21770-21770/com.ravelinx.prueba I/System.out: Test0
07-31 19:02:58.128 21770-21770/com.ravelinx.prueba I/System.out: Test1
07-31 19:02:58.505 21770-21770/com.ravelinx.prueba I/System.out: Test0
07-31 19:02:58.536 21770-21770/com.ravelinx.prueba I/System.out: Test1
07-31 19:02:58.569 21770-21770/com.ravelinx.prueba I/System.out: Test2

When deleting 2 elements there were no logs

Then logs when adding 2 elements again:

07-31 19:04:24.426 22679-22679/com.ravelinx.prueba I/System.out: Test0
07-31 19:04:24.467 22679-22679/com.ravelinx.prueba I/System.out: Test3
07-31 19:04:24.727 22679-22679/com.ravelinx.prueba I/System.out: Test0
07-31 19:04:24.769 22679-22679/com.ravelinx.prueba I/System.out: Test3
07-31 19:04:24.787 22679-22679/com.ravelinx.prueba I/System.out: Test4

Here is a video showing the issue:

UPDATE Suspicious on setHasFixedSize(true) causing the whole issue to the existing code base itself removing this line should work.


Add addItem() something like this to the RecyclerViewAdapter.java

public void addItem(String item, int position) {
    this.mDataset.add(position, item);
    notifyItemInserted(position);
}

And replace body of btnNewExercise.setOnClickListener() as below

{
   exercises.add("Test" +i);
   i++;
   adapter.addItem("test", adapter.getCount());
}