Change cursor in CursorAdapter

I am trying to change Cursor in CursorAdapter as follows:

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

Unfortunately, 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 the contents of the CursorAdapter without creating a new one.

+4
source share
2 answers

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

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

changeCursor() will close the previous cursor, which is still controlled by Activity, this is probably the reason you get the exception. You can try calling stopManagingCursor() old cursor before calling changeCursor() .

+2
source

All Articles