1. QuickItemRenderer
Create your RecyclerView items using QuickItemRenderer class. There is just one method to override onBind(int position T object). This method binds the view with your model at a position inthe list.
@QuickLayout(R.layout.item_my_model) public class ExampleQuickItemRenderer extends QuickItemRenderer<MyModel> { private TextView mTextView; public ExampleQuickItemRenderer(View itemView) { super(itemView); mTextView = (TextView) itemView.findViewById(R.id.txt_label); } @Override public void onBind(int position, MyModel myModel) { mTextView.setText(myModel.getLabel()); } }
2. QuickAdapter
2.1 SimpleQuickAdapter
Simple class to register a QuickItemRenderer into a quick adapter. SimpleQuickAdapter extends QuickAdapter
SimpleQuickAdapter<Ineatien, IneatienQuickItemRenderer> simpleQuickAdapter = new SimpleQuickAdapter<>(ineatienList, IneatienQuickItemRenderer.class); recyclerView.setAdapter(simpleQuickAdapter);
2.2 QuickAdapter
Simple class to register multi types of QuickItemRenderer within the same adapter. Each type's class must be pre-registered. Then fill a cell using setQuickAdapterTypeFactory. The parameter is a listener letting you implement the logic to select the correct type of QuickItemRenderer at a position.
QuickAdapter<Ineatien> quickAdapter = new QuickAdapter<>(ineatienList); // register two item renderer quickAdapter.registerHolder(IneatienQuickItemRenderer.class); quickAdapter.registerHolder(NewIneatienQuickItemRenderer.class); // affect renderer from item at position quickAdapter.setQuickAdapterTypeFactory((position, ineatien) -> { if (ineatien.isNew()) { return NewIneatienQuickItemRenderer.class; } return IneatienQuickItemRenderer.class; }); recyclerView.setAdapter(quickAdapter);
3. Click Listener
Register click listener on cells with setOnItemClickListener(...)
SimpleQuickAdapter<Ineatien, IneatienQuickItemRenderer> adapter = new SimpleQuickAdapter<>(values, IneatienQuickItemRenderer.class); adapter.setOnItemClickListener((rv, view, position, ineatien) -> { Toast.makeText(context, ineatien.toString(), Toast.LENGTH_LONG).show(); });
3. Header / Footer
It's possible to affect one header and footer into an adapter. Two implementations are available HeaderQuickItemRenderer and FooterQuickItemRenderer. In these classes the method onBind has not parameter.
// MyHeaderItemRenderer.java @QuickLayout(R.layout.item_header) public class MyHeaderItemRenderer extends HeaderQuickItemRenderer { public HeaderIneatItemRenderer(View itemView) { super(itemView); } @Override protected void onBind() { // ... } } // MainActivity.java QuickAdapter<Model> adapter = new QuickAdapter<>(list); quickAdapter.registerHeader(MyHeaderItemRenderer.class); quickAdapter.registerFooter(MyFooterItemRenderer.class);
4. Gradle
Available in maven central
dependencies { compile 'com.ineat-group:quick-adapter:1.0.2' }