Android 设置为SimpleCursorAdapter时无法关闭光标
我正在执行某些数据库操作,然后将光标附加到我的ListActivity上的SimpleCursorAdapter for display列表。如果我在finally块(或下面代码之后的任何地方)中关闭光标,列表中将不显示任何内容Android 设置为SimpleCursorAdapter时无法关闭光标,android,Android,我正在执行某些数据库操作,然后将光标附加到我的ListActivity上的SimpleCursorAdapter for display列表。如果我在finally块(或下面代码之后的任何地方)中关闭光标,列表中将不显示任何内容 SimpleCursorAdapter scAdapter = new SimpleCursorAdapter(this, R.layout.list_row, cursor, new String[] { Constants.
SimpleCursorAdapter scAdapter = new SimpleCursorAdapter(this,
R.layout.list_row, cursor,
new String[] { Constants.KEY_TITLE }, new int[] { R.id.text1 });
如果光标未关闭,当活动向另一个活动发出请求或被钝化时,Android将抛出异常
PS我试图在onPause()内关闭光标,但android在调用onPause之前发出了抱怨。您必须在finally块上打开光标 你错过了参加活动的机会
startManagingCursor(cursor);
这将确保活动为您管理光标。您必须在最后一个块上保持光标打开状态
SimpleCursorAdapter scAdapter = new SimpleCursorAdapter(this,
R.layout.list_row, db.query(...),
new String[] { Constants.KEY_TITLE }, new int[] { R.id.text1 });
你错过了参加活动的机会
startManagingCursor(cursor);
这将确保活动为您管理光标。这只解决了部分问题。当我启动管理游标(游标)时;然后点击菜单键>菜单活动>返回键我得到:
ERROR/Cursor(4047): Invalid statement in fillWindow()
SimpleCursorAdapter scAdapter = new SimpleCursorAdapter(this,
R.layout.list_row, db.query(...),
new String[] { Constants.KEY_TITLE }, new int[] { R.id.text1 });
这只解决了部分问题。当我启动管理游标(游标)时;然后点击菜单键>菜单活动>返回键我得到:
ERROR/Cursor(4047): Invalid statement in fillWindow()
我通过动态创建光标来解决这个问题。SimpleCursorAdapter似乎将为您管理光标
SimpleCursorAdapter scAdapter = new SimpleCursorAdapter(this,
R.layout.list_row, db.query(...),
new String[] { Constants.KEY_TITLE }, new int[] { R.id.text1 });
此外,自从Pentium10发布后,startManagingCursor就被弃用了。我通过动态创建光标来解决这个问题。SimpleCursorAdapter似乎将为您管理光标
SimpleCursorAdapter scAdapter = new SimpleCursorAdapter(this,
R.layout.list_row, db.query(...),
new String[] { Constants.KEY_TITLE }, new int[] { R.id.text1 });
自Pentium10发布以来,startManagingCursor也被弃用。对于偶然发现的人,在Android的新版本上,
startManagingCursor
被弃用。对于偶然发现的人,在Android的新版本上,startManagingCursor
被弃用。