0
從我的ContentProvider
獲取的數據未加載到屏幕中。我不知道問題在哪裏,尤其是在onLoadFinished
中傳遞的數據變量不爲空,並且ContentProvider
的查詢方法也不會返回null。這裏是Loader回調的實現。數據未加載到片段
的data.getCount()在onLoadFinished返回0
@Override
public void onActivityCreated(Bundle savedInstanceState) {
getLoaderManager().initLoader(MOVIE_LOADER, null, this);
super.onActivityCreated(savedInstanceState);
}
@Override
public android.support.v4.content.Loader<Cursor> onCreateLoader(int id, Bundle args) {
android.support.v4.content.Loader cursorLoader;
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
pref = preferences.getString("sort_method", "0");
String a;
if (pref.equals("0")) {
cursorLoader = new android.support.v4.content.CursorLoader(getActivity(), MovieContract.MostPopMovieEntry.CONTENT_URI,
new String[]{MovieContract.MostPopMovieEntry._ID, MovieContract.MostPopMovieEntry.COLUMN_POSTER_PATH},
null,
null,
null);
} else {
cursorLoader = new android.support.v4.content.CursorLoader(getActivity(), MovieContract.TopRatedMovieEntry.CONTENT_URI,
new String[]{MovieContract.TopRatedMovieEntry._ID, MovieContract.TopRatedMovieEntry.COLUMN_POSTER_PATH},
null,
null,
null);
}
if (cursorLoader != null) {
a = "cursorLoader initiated in onCreateLoader is not null";
} else {
a = "cursorLoader initiated in onCreateLoader is null";
}
Log.d(LOG_TAG, a);
return cursorLoader;
}
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
Log.d(LOG_TAG, data.getCount() + " rows loaded");
if (data != null) {
Log.d(LOG_TAG, "Data received onLoadfinished is no null");
}else{
Log.d(LOG_TAG, "Data received onLoadfinished is null");
}
movieAdapter.swapCursor(data);
}
查詢不返回null,在onCreateLoader
開始沒有返回null裝載機,無論是在onLoadFinished
返回空接收到的數據。
任何想法可能導致數據不被加載到Fragment
的問題是什麼?
首先在initLoader方法之前放置super.onActivityCreated。你在cursorLoader中放置了一些斷點,結果可能是什麼?你是否對數據庫檢查了它實際返回一些數據的查詢? – Aegis