'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 CursorAdapter without creating new one.
Solution 1:[1]
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);
}
Solution 2:[2]
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().
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | sealskej |
| Solution 2 | Nikolay Elenkov |
