【发布时间】:2022-01-02 13:51:31
【问题描述】:
出于某种特殊原因,我向光标添加了一个虚拟内容。但是在用户执行了一些操作后,我想删除我添加到光标的虚拟内容。有没有办法这样做?
https://stackoverflow.com/a/18154738/14705856,这是我在 SO 上找到的解决方案之一。但问题是我使用的表有很多列。那么有没有办法复制所有行值而不是将它们添加为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());
}
【问题讨论】:
标签: java android android-contentprovider android-cursor