How to update RecyclerView Adapter Data?

前端 未结 13 2314
误落风尘
误落风尘 2020-11-22 03:48

Trying to figure out what is the issue with updating RecyclerView\'s Adapter.

After I get a new List of products, I tried to:

  1. Update t

13条回答
  •  礼貌的吻别
    2020-11-22 04:33

    I'm working with RecyclerView and both the remove and the update work well.

    1) REMOVE: There are 4 steps to remove an item from a RecyclerView

    list.remove(position);
    recycler.removeViewAt(position);
    mAdapter.notifyItemRemoved(position);                 
    mAdapter.notifyItemRangeChanged(position, list.size());
    

    These line of codes work for me.

    2) UPDATE THE DATA: The only things I had to do is

    mAdapter.notifyDataSetChanged();
    

    You had to do all of this in the Actvity/Fragment code not in the RecyclerView Adapter code.

提交回复
热议问题