RecyclerView with multiple view types https://github.com/vivchar/RendererRecyclerViewAdapter
mRecyclerViewAdapter = new RendererRecyclerViewAdapter(getContext());
mRecyclerViewAdapter.enableDiffUtils();
mRecyclerViewAdapter.registerRenderer(new YourViewBinder());
//mRecyclerViewAdapter.registerRenderer(new OtherYourViewBinder());
mRecyclerViewAdapter.setItems(getYourItems());
public class YourModel implements ViewModel {
String getTitle() {...} //your method
int getTitleColor() {...} //your method
Bitmap getImage() {...} //your method
boolean isImageVisible() {...} //your method
boolean isChecked() {...} //your method
}
public class YourViewBinder extends ViewBinder<YourModel> {
public YourViewBinder() {
super(
R.layout.your_model_layout, //your item layout
YourModel.class, //your model class
(model, finder, payloads) -> finder
.setText(R.id.title, model.getTitle())
.setTextColor(R.id.text, model.getTitleColor())
.setImageBitmap(R.id.image, model.getImage())
.setVisible(R.id.image, model.isImageVisible())
.setOnClickListener(R.id.button, new OnClickListener() {
//...
})
.setChecked(R.id.check, model.isChecked())
.find(R.id.custom, new ViewProvider<CustomView>() {
//...
})
);
}
}
dependencies {
compile 'com.github.vivchar:RendererRecyclerViewAdapter:2.5.0'
}
<LinearLayout ... >
<TextView android:id = "@+id/title" ... />
<ImageView android:id = "@+id/image" ... />
<Button android:id = "@+id/button" ... />
<CheckBox android:id = "@+id/check" ... />
<CustomView android:id = "@+id/custom" ... />
</LinearLayout>