Closed fredo- closed 7 years ago
you're setting the models in buildView
, not bind
.
buildView should just create the view, bind
is where you update data on the view
Look at CarouselModel
more carefully in the sample.
I've also been meaning to write up a Carousel sample in the wiki
Got it working, had to create new class EventList
that extends RecyclerView
just like the sample app uses Carousel
, where the state seems to be being saved.
Here's the updated ListModel
:
@EpoxyModelClass
public abstract class ListModel extends EpoxyModelWithView<EventList> {
@EpoxyAttribute
List<? extends EpoxyModel<?>> models;
@Override
public boolean shouldSaveViewState() {
return false;
}
@Override
protected EventList buildView(ViewGroup parent) {
EventList eventList = new EventList(parent.getContext(), null);
return eventList;
}
@Override
public void bind(EventList eventList) {
eventList.setModels(models);
}
}
And here's EventList
:
public class EventList extends RecyclerView {
private final LinearLayoutManager layoutManager;
private SimpleEpoxyController controller;
public EventList(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
setHasFixedSize(true);
layoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false);
setLayoutManager(layoutManager);
}
public void setModels(List<? extends EpoxyModel<?>> models){
if (controller == null) {
controller = new SimpleEpoxyController();
controller.setSpanCount(1);
setAdapter(controller.getAdapter());
}
controller.setModels(models);
}
}
Thanks @elihart!!!
nice :) I'd highly recommend also clearing the models in unbind btw to clean up resources. the sample app shows that
Hey guys love the library, great work!
I'm having some problems updating views once they're set up though.
I'm trying to set up a list and change its contents based on state on the UI. I have my callbacks and models working properly, but when I call
setData()
and the ModelGroups are built and the Models are created, the list doesn't update with the new data.We tried using the pattern seen in the sample app with the colors in the carousels, and the pattern used in the Epoxy Controller section of the Wiki (this second one does not work and throws an exception that we should be using
setData()
instead)Here's the controller.buildModels():
This is how I set up the Models for the List that we're trying to update:
The first time we call
setModels()
everything is drawn correctly, but when we create a different list (with fewerListEventModel
s) the views do not change. From the sample app and the documentation, the views inlistModel
should update when we pass to it a different list ofListEventModel
s but it's not updating.Here's the ListModel declaration just in case: