-
Notifications
You must be signed in to change notification settings - Fork 1
RecyclerViewGroupAdapter
An adapter extends RecyclerView.Adapter and has two contructors. Only support group. Default groupType is 0.viewType>=0.
继承RecyclerView.Adapter的adapter,有两个构造方法。只支持分组模式。默认分组类型是0.viewType>=0.
using this adapter,the viewType of first item must be the group type. 使用这个adapter,第一个item的viewType一定是一个groupType.
This adapter has data cache that you need to call "notifyDataChanged(List dataList)“ to udpate the data cache when the data has been changed.Other notifyItemXXXX methods from original RecyclerView.Adapter, in this adapter you should use notifyDataItemXXXX instead.
这个adapter是有数据缓存的,如果当数据发生了变化,你需要使用"notifyDataChanged(List dataList)“来更新数据。原RecyclerView.Adapter的其他notifyItemXXXX方法,在此adapter中需要用notifyDataItemXXXX来代替。
-
RecyclerViewGroupAdapter(Context context, List dataList, @LayoutRes int[] typeLayoutIds, RecyclerViewGroupTypeProcessor groupTypeProcessor)
-
RecyclerViewGroupAdapter(Context context, List dataList, @LayoutRes int[] typeLayoutIds, Integer groupType, RecyclerViewGroupTypeProcessor groupTypeProcessor)
Here is a sample:
这是一个例子:
mGroupAdapter = new RecyclerViewGroupAdapter<>(this, mDataList
, new int[]{R.layout.item_group_type, R.layout.item_list_type1}
, new RecyclerViewGroupTypeProcessor<Car>() {
@Override
public void onBindGroupViewHolder(RecyclerViewViewHolder holder, int groupPosition, Car car) {
TextView tvGroup = holder.getView(R.id.tv_group);
tvGroup.setText(car.getGroup());
}
@Override
public void onBindItemViewHolder(RecyclerViewViewHolder holder, final int groupPosition, final int itemPosition, Car car) {
TextView tvContent = holder.getView(R.id.tv_content);
tvContent.setText("Car brand:" + car.getBrand() + " / type: " + car.getTypeName());
tvContent.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(GroupListActivity.this
, "Group: " + groupPosition + "\titemPosition: " + itemPosition, Toast.LENGTH_SHORT).show();
}
});
}
@Override
public int getItemViewType(int position) {
if (mDataList.get(position).getGroup() != null)
return 0;
return 1;
}
});