RecycleView局部刷新

Posted by JamesPxy on 2018-06-26

1.第一种方法:

1
2
3
4
5
6
7
8

public final void notifyItemChanged(int position, Object payload) {
mObservable.notifyItemRangeChanged(position, 1, payload);
}

public void onBindViewHolder(VH holder, int position, List<Object> payloads) {
onBindViewHolder(holder, position);
}

关键点:在于payload 传递数据源 实现三参数的onBindViewHolder,如果payloads为空则全部刷新,不为空实现局部刷新

2.第二种方法:

1
2
3
4
5
6
RecyclerView.ViewHolder viewHolder = recyclerView.findViewHolderForAdapterPosition(position);

if (viewHolder != null && viewHolder instanceof DynamicNormalItemHolder) {
DynamicNormalItemHolder holder= (DynamicNormalItemHolder) viewHolder;
holder.setDynamicDetailContentText();
}


支付宝打赏 微信打赏

赞赏一下