-
Notifications
You must be signed in to change notification settings - Fork 1
RecyclerViewMultipleTypeProcessor
arjinmc edited this page Jul 23, 2020
·
2 revisions
An abstract class to callback ReyclverViewAdapter.ViewHolder.It's support for multiple viewType, fits for ReyclerViewAdapter.
一个抽象类来回调ReyclverViewAdapter.ViewHolder。只支持多种viewType,可用于ReyclerViewAdapter。
You can get the ViewHolder,position(item position of the adapter) and the Object which position of the data list from the callback "onBindViewHolder".
你通过"onBindViewHolder"的回调得到ViewHolder,item的位置和相应位置的数据object。
You need to Override the "getItemViewType()" to distinguish different types. the viewTypes is >=0. You also need to use "getItemViewType()" to distinguish different types in "onBindViewHolder()".
你需要重写"getItemViewType()"来区分不同类型。viewType的值是>=0.你还需要在"onBindViewHolder()"中通过"getItemViewType()"来区分类型。
Here is a sample:
这是一个例子:
mAdapter = new RecyclerViewAdapter<>(this, mDataList
, new int[]{R.layout.item_list_type0, R.layout.item_list_type1}
, new RecyclerViewMultipleTypeProcessor<Car>() {
@Override
public void onBindViewHolder(RecyclerViewViewHolder holder, int position, Car object) {
if(getItemViewType(position) == 0) {
TextView textView = holder.getView(R.id.tv_content);
textView.setText(object.getBrand() + "/" + object.getTypeName());
}else{
}
}
@Override
public int getItemViewType(int position) {
//define two viewTypes
if (position % 2 == 0)
return 1;
return 0;
}
});