I have a browsefragment thats displaying rows from a JSON file generated by PHP when a PHP page is called. I am trying to get the browsefragment to refresh the rows as the JSON data will be changing regularly.
Following the instructions on https://hackernoon.com/how-to-refresh-the-android-tv-browsefragment-6e4d2d3c6690, I added clear() and addAll() methods found in the ArrayOjectAdapter.
The main portion of my browseFragment is:
public class MainFragment extends BrowseSupportFragment
implements LoaderManager.LoaderCallbacks<LinkedHashMap<String, List<Video>>>{
private static final int BACKGROUND_UPDATE_DELAY = 300;
private static final String TAG = MainFragment.class.getSimpleName();
static final int GRID_ITEM_WIDTH = 300;
private static final int GRID_ITEM_HEIGHT = 200;
private final Handler mHandler = new Handler();
private ArrayObjectAdapter mRowsAdapter;
private Drawable mDefaultBackground;
private DisplayMetrics mMetrics;
private Runnable mBackgroundTask;
private Uri mBackgroundURI;
private BackgroundManager mBackgroundManager;
private CustomListRow mGridItemListRow;
private LoaderManager mLoaderManager;
private static final int CATEGORY_LOADER = 123;
ArrayList<Video> mItems = null;
private ArrayList<CustomListRow> mVideoListRowArray;
private static final int VIDEO_ITEM_LOADER_ID = 1;
private static PicassoBackgroundManager picassoBackgroundManager = null;
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
prepareBackgroundManager();
setupUIElements();
loadRows();
setRows();
mLoaderManager = LoaderManager.getInstance(this);
mLoaderManager.initLoader(VIDEO_ITEM_LOADER_ID, null, this);
setupEventListeners();
prepareEntranceTransition();
picassoBackgroundManager = new PicassoBackgroundManager(getActivity());
picassoBackgroundManager.updateBackgroundWithDelay("http://twende.phidampalmgardens.com/images/bkground/background1.jpg");
updateRecommendations();
if(mVideoListRowArray != null) {
new Handler().postDelayed(new Runnable() {
public void run() {
//mLoaderManager.restartLoader(CATEGORY_LOADER, null, MainFragment.this);
mRowsAdapter.clear();
mRowsAdapter.addAll(0, mVideoListRowArray);
}
}, 2000);
}
}
Unfortunately, I still cannot get the rows to refresh/update without having to close and reopen the app
Try adding the
mRowsAdapter.notifyDataSetChanged();
statement: