RecyclerView since the launch of 2015, there have been a variety of open source libraries in open source, varied, but, in the process of use is really suitable for you? I am not sure about this, however, I feel that I haven’t found a library that is more convenient to use, so I created this library ExpandRecyclerView.

In 2015, I created a RecyclerView separation line library called RecyclerViewDecoration. Although the 1.x version has many properties, it is not very convenient to use. It was not until 2017 that I changed to Builder 2.x version and optimized the algorithm. At the same time, some friends raised some new requirements for me. Up to now, there are also some new requirements, which I will update in the future.

Including now to introduce the ExpandRecyclerView, RecyclerViewDecoration content is also merged here from version 1.3. More splitter and Adapter-integrated apis are coming. The purpose of this library is simply to minimize the amount of code used by users. It is not clear how to use it, you can refer to the example in sample, the following is just a brief introduction.

ExpandRecyclerView currently mainly contains several parts:

Adapter

  1. RecyclerViewAdapter

This Adapter can support both single items and multiple items.

Example :(single item)

RecyclerViewAdapter adapter = new RecyclerViewAdapter<>(this, Arrays.asList(titles) , R.layout.item_main_list , new RecyclerViewSingleTypeProcessor<String>() { @Override public void onBindViewHolder(RecyclerViewViewHolder holder, final int position, String str) { TextView textView = holder.getView(R.id.tv_content); textView.setText(str); }});Copy the code

Example :(multiple items)

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; }});Copy the code
  1. RecyclerViewGroupAdapter

Note that the first item of the Adapter must be a group type.

Ex. :

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; }});Copy the code

ItemDecoration

Before the introduction of https://blog.csdn.net/arjinmc/article/details/74508483

There are also new RecyclerViewGroupItemDecoration group line. You can see it used in one way in the GroupGridActivity section of sample.

Style

Convert some general RecyclerView layout.

See the Wiki for more details on the API.

If you find a bug, or if you have any new ideas, please email me. [email protected]