I want to re-load some of the rows data in a browse fragment.
Basically I want to reset the adapter data without causing a flash like effect in the browse fragment. Any idea how it can be done?
Something like notifyDataSetChanged()
in list view.
Thanx
This will refresh data without losing current position:
for (int i = 0; i < mAdapter.size(); i++) {
ListRow listRow = ((ListRow) mAdapter.get(i));
ArrayObjectAdapter listRowAdapter = ((ArrayObjectAdapter) listRow.getAdapter());
if (listRowAdapter.size() > 0) {
listRowAdapter.notifyArrayItemRangeChanged(0, listRowAdapter.size());
}
}
You can create your own adapter and add a new replaceAll() method.
public void replaceAll(Collection items){
int itemsCount = items.size();
if (itemsCount == 0){
return;
}
mItems.clear();
mItems.addAll(index, items);
notifyItemRangeChanged(0, itemsCount);
}
complete source:link
I answered something similar in this question: Dynamically add more cards in a list Row android TV leanback
I'll copy my answer from there. Hopefully this helps.
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, CumulusTV, 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();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With