RecyclerView 通过adapter设置payload
,可以实现局部刷新列表中某个条目中的一小部分ui:
notifyItemRangeChanged(int positionStart, int itemCount, @Nullable Object payload)
上面是adapter的局部刷新方法。
adapter需重写下面的方法,并在方法里实现局部刷新:
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position, @NonNull List<Object> payloads) {
DebugLog.e("adapter", "onBindViewHolder:" + payloads + ";position=" + position);
if (payloads != null && !payloads.isEmpty()) {
//局部刷新
String payload = (String) payloads.get(0);
DebugLog.e("detail", "onBindViewHolder:payload=" + payload);
} else {
onBindViewHolder(holder, position);
}
}