Comments (3)
It is the question for the stackoverflow. Please provide a link to the stackoverflow question and we will continue there.
What do you do after clicking at the remove button? Looks like you don't remove a child item in your list.
FYI: In the areContentsTheSame
method you should use oldItem.equals(newItem)
and you should override equals
method in ParentModel
and ChildItem
. It is not critical in your case but is not correct in general. See Google Documentation about DiffUtil.
from rendererrecyclerviewadapter.
Thanks for your reply, I'm still trying to figure out how to post to stackoverflow, so please allow me to ask my question here for the time being.
I'd really appreciate if you could help me proceed, thank you!
=====================================================================
Here is my parent model:
public class ParentModel extends DefaultCompositeViewModel {
private String id;
public ParentModel(String id, List<ChildModel> items) {
super(items);
this.id = id;
}
public String getId() {
return id;
}
@Override
public List<ChildModel> getItems() {
return (List<ChildModel>) super.getItems();
}
public boolean equals(Object other) {
if (other instanceof ParentModel) {
ParentModel pm = (ParentModel) other;
return pm.getId() == this.getId();
}
return false;
}
=====================================================================
Here is my child model:
public class ChildModel implements ViewModel {
private String id;
private String parent_id;
public ChildModel(String id, String parent_id) {
this.id = id;
this.parent_id = parent_id;
}
public String getId() { return id; }
public String getParentId() {
return parent_id;
}
public boolean equals(Object other) {
if (other instanceof ChildModel) {
ChildModel cm = (ChildModel) other;
return cm.getId() == this.getId();
}
return false;
}
}
=====================================================================
Here is my ParentDiffCallback (I changed areContentsTheSame based on your advice):
public class ParentDiffCallback extends DefaultDiffCallback {
@OverRide
public boolean areItemsTheSame(@nonnull final ParentModel oldItem, @nonnull final ParentModel newItem) {
return oldItem.getId().equals(newItem.getId());
}
@Override
public boolean areContentsTheSame(@NonNull final ParentModel oldItem, @NonNull final ParentModel newItem) {
return oldItem.equals(newItem);
}
@Nullable
@Override
public Object getChangePayload(@NonNull final ParentModel oldItem, @NonNull final ParentModel newItem) {
return null;
}
}
=====================================================================
Here is my child view renderer (I did remove child item with the click, please tell me if I did it wrong):
parentModels is the list of parent models:
List parentModels = new ArrayList();
private ViewRenderer childViewRenderer() {
ViewBinder.Binder childBinder = new ViewBinder.Binder() {
@OverRide
public void bindView(@nonnull ChildModel model, @nonnull ViewFinder finder, @nonnull List payloads) {
finder.setOnClickListener(R.id.ibDelete, new View.OnClickListener() {
@OverRide
public void onClick(View v) {
String parent_id = model.getParentId();
for (ParentModel pm : parentModels) {
if (pm.getId().equals(parent_id)) {
pm.getItems().remove(model);
}
}
parentAdapter.setItems(parentModels);
}
});
}
};
return new ViewBinder<>(
R.layout.child_item,
ChildModel.class,
childBinder
);
}
=====================================================================
Here is my parent view renderer:
private ViewRenderer parentViewRenderer() {
return new CompositeViewBinder(
R.layout.parent_item,
R.id.rvChild,
ParentModel.class,
(model, finder, payloads) -> finder
.setOnClickListener(R.id.ibDelete, (v -> onLocationDeleteClicked(model)))
).registerRenderer(childViewRenderer());
}
from rendererrecyclerviewadapter.
Looks fine, need to debug and investigate, please use the stackoverflow. I have no time to debug your code. Thanks.
from rendererrecyclerviewadapter.
Related Issues (20)
- How to use with Android databinding HOT 1
- which versioin should be used for ANDROID SDK 27? HOT 1
- migration to ListAdapter HOT 4
- Simple Android Or Androidx ? HOT 1
- Any plan to upgrade to Kotlin? HOT 1
- Access CompositeViewBinder adapter HOT 1
- how to access composite item recyclerview for snap HOT 6
- add CustomViewFinder support HOT 2
- add setOnClickListener without View paramenter HOT 1
- Drag and drop support HOT 8
- wrap RecyclerView to WeakReference HOT 1
- How to add a custom paging adapter HOT 1
- ViewState overrides value from Model HOT 2
- setItems() always replace current items HOT 1
- Unable to resolve model methods ? HOT 4
- How to get item position after updating items HOT 7
- How to create a StargazerViewRenderer with version 3.0 ? HOT 6
- Paging 3.0 or Load More Indicator ? HOT 1
- change composite item in parent HOT 1
- ViewState not working HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rendererrecyclerviewadapter.