Dynamically add more cards in a list Row android TV leanback

余生长醉 提交于 2020-01-15 11:58:12

问题


I am working on a Android TV app for quite some time now and I have come far while working on it. I am trying to develop an app like popcorn time but it's for Google nexus TV box. The problem where I am stuck in, is really simple but even after a lot of effort I am still unable to figure out the solution. I am fetching the json data from my database which has all the movies details and links and this works perfectly fine. Over all app view

Now those who have used the you tube app on Android TV must have noticed that it was built on leanback and as you scroll down in a listrow more cards are added into a row and likewise the app made the json calls to fetch more data according to the category we are scrolling in. (that's what I want to do)

Right now it is impossible, if I request for large data it takes a long time to fetch everything from the server so I have devised a way via which I can make json calls on scroll but I am unable to present them in a listrow at runtime.


回答1:


To add items to a presenter;

CardPresenter channelCardPresenter = new CardPresenter();
ArrayObjectAdapter channelRowAdapter = new ArrayObjectAdapter(channelCardPresenter);
channelRowAdapter.add(new Movie("Movie Title"));
HeaderItem header = new HeaderItem(0, "My Channels");
mRowsAdapter.add(new ListRow(header, channelRowAdapter));

Of course this may only work for the first time you're creating the UI. Future times may not do this. In my app, https://github.com/Fleker/CumulusTV/blob/master/app/src/main/java/com/felkertech/n/tv/LeanbackFragment.java, I create a method that will be called each time I want to do a full redraw of the app:

public void refreshUI() {
    prepareBackgroundManager();
    setupUIElements();
    loadRows(); //Generate and populate all the rows
    setupEventListeners();
}



回答2:


I have been working with android TV Leanback library from past 7 or 8 months. And I have developed my own presenter class via which you can load more cards dynamically on scroll, but its not possible using Leanback Library, ListAdapter updateds a single row and than move to next category to update it's cards. which take time on run time.

I have used the below answer to create my own presenter class. The Trick while implementing endless loading on scroll is that you have to create two AysncTasks.

Have a look at at post 34

Lazy download images into gridView

it will a little time taking but you will get the idea.



来源:https://stackoverflow.com/questions/33842404/dynamically-add-more-cards-in-a-list-row-android-tv-leanback

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!