开发者

Changing of Cursor in CursorAdapter

I am trying to change Cursor in CursorAdapter this way:

Cursor newCursor = compiledStatement.getCursor();
startManagingCursor(newCursor);
adapter.changeCursor(newCursor);

Unfortunatelly I get this exception:

java.lang.IllegalStateException: attempt to re-open an already-closed object:
     android.database.sqlite.SQLiteQuery

According to other topics, it should be possible to change content of CursorAdapt开发者_如何转开发er without creating new one.


I have found the problem. My CursorAdapter implements SectionIndexer, so I had to owerwrite changeCursor() method and reset the Cursor for AlphabetIndexer.

@Override
public void changeCursor(Cursor cursor) {
    mIndexer.setCursor(cursor);
    super.changeCursor(cursor);
}


changeCursor() will close the previous Cursor, which is still managed by the Activity, that is probably the reason you are getting the exception. You might try calling stopManagingCursor() on the old cursor before you call changeCursor().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜