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 ... :-)
Glenn bech
source share