Skip to content

Repository files navigation

RowAdapter

  • 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 ListView and RecyclerView implementations

Basic Usage

  1. 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);
}
}
}
  1. 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));
}
  1. Instantiate an Adapter and provide it to either a ListViewRecyclerView or ExpandableListView
mRecyclerView.setAdapter(newRecyclerRowAdapter(this, rows));
  1. Handle click events with a RowClickHandler to support multiple RowType click events or using OnRowClickListener for single click events.
RowClickHandlerclickHandler = newRowClickHandler()
.put(SampleRecyclerRow.class, newOnRowClickListener<SampleRecyclerRow>() {
@OverridepublicvoidonRowClick(SampleRecyclerRowtypedRow, Viewview, intposition) {
mToast.setText("SampleRecyclerRow, pos: " + position);
mToast.show();
}
})
...

Further Usage

Please refer to this blog post or the sample module for a complete set of usages.

About

An Android Library to improve productivity and reusability of adapter code

Resources

Stars

1 star

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages