我有一個RecyclerView
,我用它來顯示從使用LoaderManager
內容提供商獲取的數據。它工作正常,但我發現我當大數據加載下面執行一些性能問題,有一個在爲我使用的是ViewPager
加載承載這種方法與數據RecyclerView從LoaderManager
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
Favorites = new ArrayList<>();
if (cursor != null) {
while (cursor.moveToNext())
Favorites.add(FavoritesModel.fromCursor(cursor));
}
adapter = new FavoritesAdapter(getActivity(),Favorites);
favoritesRecyclerView.setAdapter(adapter);
}
所以Fragment
顯示的數據滯後我選擇要做到以下幾點:
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
........
adapter = new FavoritesAdapter(getActivity(),Favorites);
favoritesRecyclerView.setAdapter(adapter);
........
,然後在onLoadFinished
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
Favorites = new ArrayList<>();
if (cursor != null) {
while (cursor.moveToNext())
Favorites.add(FavoritesModel.fromCursor(cursor));
}
adapter.notifyDataSetChanged();
}
使用這種沒有東西顯示出來。什麼是自onLoadFinished
問題總是打來電話,我知道它一直被稱爲UI線程
好吧@Blackbelt回答爲什麼你不得不空列表...現在有關滯後...它很簡單... **第一種解決方案:(優先)不使用模型**(作爲迭代光標和創建模型對象創建滯後)...直接在適配器中使用光標(谷歌的如何連接光標和RecyclerView的適配器).... **第二種解決方案是** ...在主線程之外移動當前的'onLoadFinished'代碼... – Selvin
這是我想到的不過RecyclerView的適配器實現過濾,允許搜索小工具進行搜索,使用適配器光標將有可能做到這一點 –
嗯過濾用裝載機是很容易的使用'restartLoader' – Selvin