Last active
March 2, 2018 06:42
-
-
Save vivchar/d96e750c26bdbb200e7cdb40c80e3e0a to your computer and use it in GitHub Desktop.
RecyclerView with multiple view types https://github.com/vivchar/RendererRecyclerViewAdapter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dependencies { | |
compile 'com.github.vivchar:RendererRecyclerViewAdapter:2.5.0' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mRecyclerViewAdapter = new RendererRecyclerViewAdapter(getContext()); | |
mRecyclerViewAdapter.enableDiffUtils(); | |
mRecyclerViewAdapter.registerRenderer(new YourViewBinder()); | |
//mRecyclerViewAdapter.registerRenderer(new OtherYourViewBinder()); | |
mRecyclerViewAdapter.setItems(getYourItems()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>() { | |
//... | |
}) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment