I have a ListView in a dialog and an EditText to filter my list for CustomerCodes,i’ve implemented my filter query with a TextWatcher and in onTextChanged() i’ve changed my old Cursor with
Cursor FilteredCPCodeList = CustomerDBAdapter.instance.CursorFilteredCPCode(s.toString()); //Retrieve Filtered CustomerCodeList
CpListadapter.changeCursor(FilteredCPCodeList);
List Filtering works Perfect with codes above but when i click on a ListItem it’s OnItemClickListener which use old Cursor cause an Exception which tells :
01-05 10:33:01.577: E/AndroidRuntime(5380): android.database.StaleDataException: Attempting to access a closed CursorWindow.Most probable cause: cursor is deactivated prior to calling this method.
i know that change cursor will close my old cursor but i don’t know how can i use StopManagingCursor on my old cursor(or another soloution) to solve this Issue.i’ve tried this code on onTextChanged() but it doesn’t work either
Cursor OldCursor = CpListadapter.getCursor();
stopManagingCursor(OldCursor );
any help would be appreciated,Thanks
stopManagingCursor()is deprecated and not recommended anymore. You should be usingCursorLoader. Then you can use aSimpleCursorAdapteralong with theswapCursor(Cursor)method.If you need to use your current setup, you should be able to do
CpListadapter.getCursor().close()(for example, in youronDestroy()).