首先设置recyclerView动画
mRecyclerView.setItemAnimator(new DefaultItemAnimator());
然后在Adapter中定义三个方法
public void remove(int position) {
list.remove(position);
notifyItemRemoved(position);
//刷新下标,不然下标就重复
notifyItemRangeChanged(position, list.size());
}
public void add(int position, String data) {
list.add(position, data);
notifyItemInserted(position);
//刷新下标,不然下标就不连续
notifyItemRangeChanged(position, list.size());
}
public void change(int position, String data) {
list.set(position, data);
notifyItemChanged(position);
}