- can be used as a replacement to
RecyclerView.Adapter,SpinnerAdapter,CursorAdapter,ExpandableListAdapter,ListAdapter, all while using a common interface. - aims to provide more flexibility than other adapter libraries by letting the adapter automatically handle ViewType information, simplifying your code and making it reusable
- is compatible with both
ListViewandRecyclerViewimplementations
- Create a Row Class which represents an Adapter View and handles binding of your model to the view. You have a choice of sub classes to extend from that remove boiler plate code, such as inflating from a layout resource.
publicclassSampleRecyclerRowextendsViewHolderRow<String, SampleRecyclerRow.ViewHolder> {
publicSampleRecyclerRow(Stringitem) {
super(item, R.layout.row_header);
}
@OverridepublicViewHoldercreateViewHolder(Viewview, intposition) {
returnnewViewHolder(view);
}
@OverridepublicvoidbindViewHolder(ViewHolderviewHolder, Stringitem, intposition) {
viewHolder.mTextView.setText(item);
}
staticclassViewHolderextendsRecyclerView.ViewHolder {
TextViewmTextView;
ViewHolder(Viewview) {
super(view);
mTextView = (TextView) view.findViewById(R.id.textview);
}
}
}- Instantiate a list of Rows of any type (View Type information is handled by RowAdapter):
List<SampleRecyclerRow> rows = newArrayList<SampleRecyclerRow>();
for (inti = 0; i < 17; i++) {
Stringtext = "Extra Info: " + String.valueOf(i);
rows.add(newSampleRecyclerRow(text));
}- Instantiate an Adapter and provide it to either a
ListViewRecyclerVieworExpandableListView
mRecyclerView.setAdapter(newRecyclerRowAdapter(this, rows));- Handle click events with a
RowClickHandlerto support multiple RowType click events or usingOnRowClickListenerfor single click events.
RowClickHandlerclickHandler = newRowClickHandler()
.put(SampleRecyclerRow.class, newOnRowClickListener<SampleRecyclerRow>() {
@OverridepublicvoidonRowClick(SampleRecyclerRowtypedRow, Viewview, intposition) {
mToast.setText("SampleRecyclerRow, pos: " + position);
mToast.show();
}
})
...Please refer to this blog post or the sample module for a complete set of usages.