-
Notifications
You must be signed in to change notification settings - Fork 184
Quick start with Simple Items
Vitaly Vivchar edited this page Oct 19, 2017
·
14 revisions
To create a Simple Item item you should:
- Implement the ItemModel interface
public class SimpleModel implements ItemModel {
public static final int TYPE = 12376;
private String mName;
public CategoryModel(String name) {
mName = name;
}
@Override
public int getType() {
return TYPE;
}
public String getName() {
return mName;
}
}
- Extend the RecyclerView.ViewHolder class
public class SimpleViewHolder extends RecyclerView.ViewHolder {
public TextView mName;
public SimpleViewHolder(View itemView) {
super(itemView);
mName = (TextView) itemView.findViewById(R.id.name);
}
}
- Extend the ViewRenderer class
public class SimpleViewRenderer extends ViewRenderer<SimpleModel, SimpleViewHolder> {
public CategoryViewRenderer(final int type, final 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));
}
}
- Create an instance of your
ViewRenderer
...
ViewRenderer simpleRenderer = new SimpleViewRenderer(this);
...
- Register your
ViewRenderer
in main adapter
...
mRecyclerViewAdapter = new RendererRecyclerViewAdapter();
mRecyclerViewAdapter.registerRenderer(simpleRenderer);
...