Skip to content

Quick start with Composite Items

Vitaly Vivchar edited this page Oct 19, 2017 · 17 revisions

To create a nested RecyclerView item you should:

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));
	}
}

4. Create an instance of your RecyclerViewRenderer

CompositeViewRenderer compositeRenderer = new RecyclerViewRenderer(this);

5. Determine which cells it will support

compositeRenderer.registerRenderer(simpleRenderer);
compositeRenderer.registerRenderer(simpleRenderer2);

6. Register your CompositeViewRenderer in main adapter

mRecyclerViewAdapter = new RendererRecyclerViewAdapter();
mRecyclerViewAdapter.registerRenderer(compositeRenderer);