问题
I want to display two different types of cards in the same row (ListRow)
.
I tried to modify the Presenter class by adding viewType similar to dealing with displaying multiple row types in RecyclerVew
but it did not work.
I tried digging into the Presenter and ArrayObjectAdapter
code but there is no obvious option to achieve this. If someone has done this then please point me in the right direction.
回答1:
You can use ClassPresenterSelector to show different types of cards in the same row
Example
ClassPresenterSelector selector = new ClassPresenterSelector();
YourDetailTypePresenter detailPresenter = new YourDetailTypePresenter();
YourImageTypePresenter imagePresenter = new YourImageTypePresenter();
selector.addClassPresenter(DetailsOverviewRow.class, detailPresenter);
selector.addClassPresenter(ImageOverviewRow.class, imagePresenter);
mRowsAdapter = new ArrayObjectAdapter(selector);
来源:https://stackoverflow.com/questions/47953258/adding-multiple-presenters-to-arrayobjectadapter-of-android-leanback