Android - how to remove an item from a cursor?

Let's say I make the following pointer to call the call log:

String[] strFields = { android.provider.CallLog.Calls.NUMBER, android.provider.CallLog.Calls.TYPE, android.provider.CallLog.Calls.CACHED_NAME, android.provider.CallLog.Calls.CACHED_NUMBER_TYPE }; String strOrder = android.provider.CallLog.Calls.DATE + " DESC"; Cursor mCallCursor = getContentResolver().query( android.provider.CallLog.Calls.CONTENT_URI, strFields, null, null, strOrder ); 

Now, how can I delete the item I'm in this cursor? It can also be a cursor listing music, etc. So I have to ask - is this possible? I can understand for some cursors that third-party applications will not be deleted.

Thanks.

+3
java android cursor
source share
2 answers

Sorry, you cannot delete from the cursor.

You must either use your ContentResolver or some kind of SQL call.

+8
source share

You can trick MatrixCursor. Using this strategy, you copy the cursor and skip one line that you want to exclude. This is obviously not very effective for large cursors, since you will save the entire data set in memory.

You must also repeat the String array of column names in the MatrixCursor constructor. You must save this as a constant.

  //TODO: put the value you want to exclude String exclueRef = "Some id to exclude for the new"; MatrixCursor newCursor = new MatrixCursor(new String[] {"column A", "column B"); if (cursor.moveToFirst()) { do { // skip the copy of this one .... if (cursor.getString(0).equals(exclueRef)) continue; newCursor.addRow(new Object[]{cursor.getString(0), cursor.getString(1)}); } while (cursor.moveToNext()); } 

I am constantly fighting this; Trying to create your applications only with the help of cursors and content providers, trying to avoid matching objects as long as possible. You should see some of my ViewBinders ... :-)

+4
source share

All Articles