gpt4 book ai didi

android - 未调用 Loadmanager onLoadFinished

转载 作者:IT王子 更新时间:2023-10-29 06:29:53 25 4
gpt4 key购买 nike

我正在尝试使用 LoaderCallBacks 从数据库加载数据。但是不会调用 loadercallbacks 中的 onLoadFinished 函数。因此,正如您在日志中看到的那样,返回的行数为 1,但列表未显示任何条目,而且正如您所见,没有调用 onLoadFinished。

SerieFragment

    public class SerieFragment extends SherlockListFragment implements            LoaderCallbacks {        private SimpleCursorAdapter adapter;        @Override        public void onCreate(Bundle savedInstanceState) {            super.onCreate(savedInstanceState);            String[] from = new String[] { DBContract.Episodes.NAME };            int[] to = new int[] { R.id.name };            Log.i("LoaderManager", "Starting...");            getLoaderManager().initLoader(0, null, this);            adapter = new SimpleCursorAdapter(getActivity(),                    R.layout.serie_list_item, null, from, to, 0);            this.setListAdapter(adapter);        }        @Override        public void onViewCreated(View view, Bundle savedInstanceState) {        }        @Override        public Loader onCreateLoader(int id, Bundle args) {            Log.i("LoaderManager", "Creating loader...");            String[] projection = { DBContract.Episodes._ID,                    DBContract.Episodes.NAME };            CursorLoader cursorLoader = new CursorLoader(this.getActivity(),                    Uri.parse(SerieProvider.CONTENT_URI + "/episodes"), projection,                    null, null, null);            return cursorLoader;        }        @Override        public void onLoadFinished(Loader loader, Cursor cursor) {            Log.i("LoaderManager",                    "Finished load entry... - Cursor: " + cursor.getCount());            adapter.swapCursor(cursor);        }        @Override        public void onLoaderReset(Loader loader) {            Log.i("LoaderManager", "Resetting loader...");            adapter.swapCursor(null);        }

Contentprovider

    public class SerieProvider extends ContentProvider {        private static DatabaseHelper database;        private static final String PROVIDER = "com.drizzlyday.apps.episotron.providers";        private static final String BASE_PATH = "serieprovider";        public static final Uri CONTENT_URI = Uri.parse("content://" + PROVIDER                + "/" + BASE_PATH);        public static final int SERIES = 1;        public static final int EPISODES = 2;        private static final UriMatcher uriMatcher;        static {            uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);            uriMatcher.addURI(PROVIDER, BASE_PATH, SERIES);            uriMatcher.addURI(PROVIDER, BASE_PATH + "/episodes", EPISODES);        }        @Override        public boolean onCreate() {            database = new DatabaseHelper(getContext());            return false;        }        @Override        public int delete(Uri uri, String selection, String[] selectionArgs) {            // TODO Auto-generated method stub            return 0;        }        @Override        public String getType(Uri uri) {            // TODO Auto-generated method stub            return null;        }        @Override        public Uri insert(Uri uri, ContentValues values) {            // TODO Auto-generated method stub            return null;        }        @Override        public Cursor query(Uri uri, String[] projection, String selection,                String[] selectionArgs, String sortOrder) {            Log.d("Provider", uri.toString());            SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();            int uriType = uriMatcher.match(uri);            switch (uriType) {            case SERIES:                Log.d("Provider", "Series");                queryBuilder.setTables(DBContract.Series.TABLE_NAME);                break;            case EPISODES:                Log.d("Provider", "Episodes");                queryBuilder.setTables(DBContract.Episodes.TABLE_NAME);                break;            default:                throw new IllegalArgumentException("Unknown URI: " + uri);            }            SQLiteDatabase db = database.getReadableDatabase();            SQLiteCursor cursor = (SQLiteCursor) queryBuilder.query(db, projection,                    selection, selectionArgs, null, null, sortOrder);            cursor.setNotificationUri(getContext().getContentResolver(), uri);            Log.d("Provider", "Cursor: " + cursor.toString()                    + " - Columncount: " + cursor.getColumnCount()                    + " - Rowcount: " + cursor.getCount());            return cursor;        }        @Override        public int update(Uri uri, ContentValues values, String selection,                String[] selectionArgs) {            // TODO Auto-generated method stub            return 0;        }
05-05 23:34:30.855: I/ActivityThread(31903): Pub com.drizzlyday.apps.episotron.providers: com.drizzlyday.apps.episotron.providers.SerieProvider
05-05 23:34:31.035: D/Serie(31903): New Serie fragment
05-05 23:34:31.040: I/LoaderManager(31903): Starting...
05-05 23:34:31.040: I/LoaderManager(31903): Creating loader...
05-05 23:34:31.055: D/AbsListView(31903): Get MotionRecognitionManager
05-05 23:34:31.060: D/AbsListView(31903): Get MotionRecognitionManager
05-05 23:34:31.080: D/dalvikvm(31903): GC_CONCURRENT freed 174K, 8% free 12340K/13383K, paused 2ms+2ms, total 16ms
05-05 23:34:31.090: D/Provider(31903): content://com.drizzlyday.apps.episotron.providers/serieprovider/episodes
05-05 23:34:31.090: D/Provider(31903): Episodes
05-05 23:34:31.100: V/SlidingMenu(31903): setting padding!
05-05 23:34:31.160: D/libEGL(31903): loaded /system/lib/egl/libEGL_mali.so
05-05 23:34:31.175: D/libEGL(31903): loaded /system/lib/egl/libGLESv1_CM_mali.so
05-05 23:34:31.175: D/libEGL(31903): loaded /system/lib/egl/libGLESv2_mali.so
05-05 23:34:31.180: D/(31903): Device driver API match
05-05 23:34:31.180: D/(31903): Device driver API version: 10
05-05 23:34:31.180: D/(31903): User space API version: 10
05-05 23:34:31.180: D/(31903): mali: REVISION=Linux-r2p4-02rel0 BUILD_DATE=Tue Oct 16 15:37:13 KST 2012
05-05 23:34:31.210: D/OpenGLRenderer(31903): Enabling debug mode 0
05-05 23:34:31.215: V/CustomViewBehind(31903): behind INVISIBLE
05-05 23:34:31.260: D/Provider(31903): Cursor: android.database.sqlite.SQLiteCursor@41b0df88 - Columncount: 2 - Rowcount: 1

最佳答案

我发现了问题。必须添加以下行来刷新列表的可绘制状态:

this.getListView().refreshDrawableState();

关于android - 未调用 Loadmanager onLoadFinished,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16389526/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com