-
Notifications
You must be signed in to change notification settings - Fork 183
Quick start with Simple Items
Vitaly Vivchar edited this page Oct 19, 2017
·
14 revisions
To create a Simple Item item you should:
1. 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;
}
}
2. 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);
}
}
3. Extend the ViewRenderer class
public class SimpleViewRenderer extends ViewRenderer<SimpleModel, SimpleViewHolder> {
public CategoryViewRenderer(int 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);
...