【问题标题】:Remove value from cursor android从光标android中删除值
【发布时间】: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


    【解决方案1】:

    由于这是临时数据,请不要将其添加到游标中,您应该将其保存在单独的哈希映射中,并通过某种方式将其映射到特定行,否则您必须将此游标转换为您的某个 bean应用程序将您的数据放在 bean 中而不是光标中。

    避免将任何不会推送到数据库的数据添加到游标。

    如果您将此数据临时写入 db,那么您必须运行单独的 SQL 查询以在对您无用时将其删除。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-08-23
      • 1970-01-01
      • 1970-01-01
      • 2012-07-30
      • 1970-01-01
      • 1970-01-01
      • 2013-02-10
      相关资源
      最近更新 更多