RecyclerView in Android changes the data notification list with animation

Normally, after we change the RecyclerView, we need to use the adapter to call the notifyDataSetChanged method to notify our list of corresponding update operations. However, RecyclerView provides us with richer operations and can be accompanied by corresponding animations. Today we will list the relevant notification methods.

1. Notify the adapter to insert data in the first item and scroll to the first item position

mPublicArray.add(0,new_item);
mAdapter.notifyItemInserted(0);//通知适配器列表在第一项插入数据
rv_dynamic.scrollToPosition(0);//让循环视图滚动到第一项所在的位置

2. Notify the adapter that the first item has changed

mPublicArray.set(position,item);
mAdapter.notifyItemChanged(position);//通知适配器列表在第几项发生变更

3. Notify the adapter that the first item has been deleted

mPublicArray.remove(position);
mAdapter.notifyItemRemoved(position);//通知适配器列表在第几项删除数据

 

Guess you like

Origin blog.csdn.net/weixin_38322371/article/details/114963767