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;

    protected void onCreate(Bundle savedInstanceState) {

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

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

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

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



And this is my adapter:

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

    private ArrayList<String> mDataset;

    public RecyclerViewAdapter(ArrayList myDataset) {
        mDataset = myDataset;

    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);

    public void onBindViewHolder(final RecyclerViewAdapter.ViewHolder viewHolder, int i) {

    public int getItemCount() {
        return mDataset.size();

    public class ViewHolder extends RecyclerView.ViewHolder{

        private TextView tv_exercise;
        private Button btnEliminarRow;

        public ViewHolder(View 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() {
                public void onClick(View view) {

        public void removeAt(int 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);

And replace body of btnNewExercise.setOnClickListener() as below

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