-
Notifications
You must be signed in to change notification settings - Fork 183
Quick start with View Binder
Vitaly Vivchar edited this page Jan 27, 2018
·
12 revisions
To create a Simple Item item you should:
1. Implement the ViewModel interface
public class SimpleModel implements ItemModel {
//your methods
}
<LinearLayout ... >
<TextView android:id = "@+id/title" ... />
<Button android:id="@+id/button" ... />
//...
</LinearLayout>
mRecyclerViewAdapter = new RendererRecyclerViewAdapter(getContext());
mRecyclerViewAdapter.registerRenderer(new ViewBinder<>(
R.layout.item_layout,
SomeModel.class,
(model, finder, payloads) -> finder
.find(R.id.custom_view, (ViewProvider<CustomView>) customView -> { ... })
.setOnClickListener(R.id.button, v -> { ... })
.setText(R.id.textView, model.getText())
.setTextColor(R.id.textView, model.getColor())
.setImageBitmap(R.id.image, model.getBitmap())
));
mRecyclerViewAdapter.registerRenderer(...); /* you can use several types of cells */
/* regular code
mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
mRecyclerView.setAdapter(mRecyclerViewAdapter);
mRecyclerViewAdapter.setItems(getItems());
mRecyclerViewAdapter.notifyDataSetChanged();
...
*/