-
Notifications
You must be signed in to change notification settings - Fork 183
Quick start with Simple Items
Vitaly Vivchar edited this page Dec 29, 2017
·
14 revisions
I recommend trying ViewBinder instead of ViewRenderer.
To create a Simple Item item you should:
1. Implement the ViewModel interface
public class SimpleModel implements ItemModel {
}
2. Extend the ViewHolder class
public class SimpleViewHolder extends ViewHolder {
public TextView mName;
public SimpleViewHolder(View itemView) {
super(itemView);
mName = (TextView) itemView.findViewById(R.id.name);
}
}
3. Extend the ViewRenderer class
public class SimpleViewRenderer extends ViewRenderer<SimpleModel, SimpleViewHolder> {
public CategoryViewRenderer(Class<RectViewModel> type, Context context) {
super(type, context);
}
@Override
public void bindView(SimpleModel model, SimpleViewHolder holder) {
holder.mName.setText(model.getName());
}
@Override
public SimpleViewHolder createViewHolder(ViewGroup parent) {
return new SimpleViewHolder(inflate(R.layout.simple_item, parent));
}
}
ViewRenderer simpleRenderer = new SimpleViewRenderer(this);
mRecyclerViewAdapter = new RendererRecyclerViewAdapter();
mRecyclerViewAdapter.registerRenderer(simpleRenderer);
Also you can register other your items:
mRecyclerViewAdapter.registerRenderer(simpleRenderer);
mRecyclerViewAdapter.registerRenderer(simpleRenderer2);
mRecyclerViewAdapter.registerRenderer(simpleRenderer3);
...