-
Notifications
You must be signed in to change notification settings - Fork 183
Quick start with Composite Items
Vitaly Vivchar edited this page Oct 19, 2017
·
17 revisions
To create a nested RecyclerView item you should:
1. Use the DefaultCompositeItemModel or extend the CompositeItemModel
public class RecyclerViewModel extends DefaultCompositeItemModel {
public static final int TYPE = 654323;
public RecyclerViewModel(List<ItemModel> items) {
super(TYPE, items);
}
}
2. Extend the CompositeViewHolder class
public class RecyclerViewHolder extends CompositeViewHolder {
public RecyclerViewHolder(View view) {
super(view);
recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
}
}
3. Implement the CompositeViewRenderer class
public class RecyclerViewRenderer extends CompositeViewRenderer<RecyclerViewModel, RecyclerViewHolder> {
public RecyclerViewRenderer(Context context) {
super(RecyclerViewModel.TYPE, context);
}
@Override
public RecyclerViewHolder createCompositeViewHolder(ViewGroup parent) {
return new RecyclerViewHolder(inflate(R.layout.item_recycler_view, parent));
}
}
CompositeViewRenderer compositeRenderer = new RecyclerViewRenderer(this);
compositeRenderer.registerRenderer(simpleRenderer);
compositeRenderer.registerRenderer(simpleRenderer2);
mRecyclerViewAdapter = new RendererRecyclerViewAdapter();
mRecyclerViewAdapter.registerRenderer(compositeRenderer);