Remove value from cursor android

0

For a particular reason I am adding a dummy content to my cursor. But after user have performed some actions I want to remove that dummy content I have added to the cursor. Is there an option to do so?

https://stackoverflow.com/a/18154738/14705856, This was one of the solutions that I found on SO. But the issue is that the table I am using has lot of columns. So is there any way to copy all the row values instead of adding them as cursor.getString(columnPosition).

   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());
        }
1

0

Since this is temporary data don't add it to the cursor instead you should either keep it in a separate hash map with a way to map it to the specific row or else you must be converting this cursor into some bean in your application put your data in the bean instead of cursor.

Avoid adding any data to cursor that you are not going to push to db.

If you are writing this data temporarily to db then you must run a separate SQL query to remove it when it is of no use to you.

2021-11-24 07:47:40

In other languages

This page is in other languages

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................