Changing of Cursor in CursorAdapter

2019-06-28 00:25发布

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 CursorAdapter without creating new one.

2条回答
虎瘦雄心在
2楼-- · 2019-06-28 01:07

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);
}
查看更多
甜甜的少女心
3楼-- · 2019-06-28 01:12

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().

查看更多
登录 后发表回答