I have implemented epoxy according epoxy Wiki.
I have several List<items>
. I update the controller with the first List<items>
, everything works fine. But then I update with the next List<items>
, data showed properly from second List<items>
in Epoxy View Models, but callbacks are not updated with new items object in listeners callbacks, they are pointing to the first List<items>
objects.
This is Epoxy controller part to build models:
@Override
protected void buildModels(List<Item> items) {
for (Item item : items) {
new ItemModel_()
.id(item.getId())
.title(item.getTitle())
.clickListener((model, parentView, clickedView, position) -> callbacks.onItemClicked(item))
.addTo(this);
}
}
In epoxy-sample I found clickListener callbacks with lambda implementation. Shown above: .clickListener((model, parentView, clickedView, position) -> callbacks.onItemClicked(item))
.
I update controller data with different data Lists of List<items>
, changing all List<items>
in controller.setData(List<items>);
according user requests.
It could happen if you use the
@ModelProp
annotation with an optionOption.DoNotHash
on theclickListener(Listener)
method. [@ModelProp(options = {Option.DoNotHash})
]This option causes the code generated in the
ItemModel_
to do not compare previous and new listeners and just use the previous one after the models were updated. Try to use@ModelProp
without options or use anOption.IgnoreRequireHashCode
instead ofOption.DoNotHash
.Also, check the generated
ItemModel_.bind(...)
method for more information.