无法使用ArrayObjectAdaptor的clear()和addAll()刷新/更新浏览片段

时间:2019-05-11 07:57:42

标签: android-tv leanback browsefragment

我有一个浏览片段,当调用PHP页面时,该片段显示PHP生成的JSON文件中的行。我正在尝试使browserfragment刷新行,因为JSON数据将定期更改。

按照https://hackernoon.com/how-to-refresh-the-android-tv-browsefragment-6e4d2d3c6690上的说明,我添加了在ArrayOjectAdapter中找到的clear()和addAll()方法。

browseFragment的主要部分是:

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);

        }

    }

不幸的是,我仍然无法关闭/重新打开应用程序而无法刷新/更新行

1 个答案:

答案 0 :(得分:0)

尝试添加mRowsAdapter.notifyDataSetChanged();语句:

mRowsAdapter.clear();
mRowsAdapter.addAll(0, mVideoListRowArray);
mRowsAdapter.notifyDataSetChanged();