Skip to content

An Android Library to improve productivity and reusability of adapter code

License

Notifications You must be signed in to change notification settings

LukeDeighton/RowAdapter

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.
public class SampleRecyclerRow extends ViewHolderRow<String, SampleRecyclerRow.ViewHolder> {
    public SampleRecyclerRow(String item) {
        super(item, R.layout.row_header);
    }

    @Override
    public ViewHolder createViewHolder(View view, int position) {
        return new ViewHolder(view);
    }

    @Override
    public void bindViewHolder(ViewHolder viewHolder, String item, int position) {
        viewHolder.mTextView.setText(item);
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        TextView mTextView;

        ViewHolder(View view) {
            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 = new ArrayList<SampleRecyclerRow>();
for (int i = 0; i < 17; i++) {
    String text = "Extra Info: " + String.valueOf(i);
    rows.add(new SampleRecyclerRow(text));
}
  1. Instantiate an Adapter and provide it to either a ListView RecyclerView or ExpandableListView
mRecyclerView.setAdapter(new RecyclerRowAdapter(this, rows));
  1. Handle click events with a RowClickHandler to support multiple RowType click events or using OnRowClickListener for single click events.
RowClickHandler clickHandler = new RowClickHandler()
.put(SampleRecyclerRow.class, new OnRowClickListener<SampleRecyclerRow>() {
    @Override
    public void onRowClick(SampleRecyclerRow typedRow, View view, int position) {
        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

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages