过滤掉来自光标项目 [英] Filter out items from cursor

查看:125
本文介绍了过滤掉来自光标项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从游标对​​象中删除一个项目,我不知道如何做到这一点(或者如果可能的话)。我真的不希望从数据库中删除的项目,只是'过滤器'它,而不是显示它,这取决于用户的设置。

I'm trying to remove an item from a cursor object, and I'm not sure how to do it (or if it's possible). I don't actually want to remove the item from the database, just 'filter' it and not display it, depending on user settings.

例如这里, FILTER_TEXT 是从应用程序preferences,它包含文本光标必须包含否则将被删除。

For example here, FILTER_TEXT is from the application preferences and it contains text that the cursor must contain or else it is removed.

Cursor mCursor = mDB.query(dbTable, new String[] {KEY_ROWID, KEY_NAME,
            KEY_URL}, null, null, null, null, null);

    if (mCursor.moveToFirst()) {
        do {
            if (!mCursor.getString(1).contains(FILTER_TEXT)) {
                // Remove cursor item here
            }
        } while (mCursor.moveToNext());
    }

我相当肯定,这是解决这个正确的方法,但我找不到任何方式从游标删除项目...

I was fairly sure this was the right way to tackle this, but I can't find any way to remove an item from a cursor...

任何帮助将是AP preciated,干杯!

Any help would be appreciated, cheers!

推荐答案

我想你可能要对其进行过滤甚至到 Cursor获取前。尝试改变产生它的查询,使这些项目甚至从未得到它。这样一来,SQLite的可以过滤掉那些不需要的东西,他们使用任何更多的资源了。

I think you might want to filter it before it even gets in to the Cursor. Try altering the query that generates it so that those items never even get in to it. This way, SQLite can filter out those unneeded things before they use up any more resources.

您可以通过发送事情查询'选择'参数'做',是这样的:

You can do this by sending things to the `selection' parameter of 'query', something like:

KEY_NAME + " LIKE '%" + FILTER_TEXT + "%'"

(这可能需要一些调整,我的SQL是生锈的。)

您可能还需要在看向 SQLQueryBuilder

You may also want to look in to SQLQueryBuilder.

至于如果可能的话,我找不到文档中的任何,会做你想要的。我觉得光标是只读的。

As to if it's possible, I couldn't find anything in the documentation that would do what you wanted. I think Cursor is read-only.

这篇关于过滤掉来自光标项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆