我在带有 DiffUtil 的 RecyclerView 适配器自定义类中使用了两个 viewType。
在那我更新数据它将更新 Diffutil getChangePayload但它会更新第一个视图类型。
如何将有效负载数据更改为TYPE_ITEM viewType?
> **CustomViewAdapter class**
private static final int TYPE_HEADER = 0;
private static final int TYPE_ITEM = 1;
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
if (viewType == TYPE_ITEM) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.home_list_items, parent, false);
return new MyViewHolder(itemView);
} else if (viewType == TYPE_HEADER) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.home_banner, parent, false);
return new HeaderView(itemView);
}
return null;
}
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position, @NonNull List<Object> payloads) {
Log.d(TAG, "onBindViewHolder: viewholder " + viewHolder);
Log.d(TAG, "onBindViewHolder: payload " + payloads);
}