Android:过滤 SimpleCursorAdapter ListView

发布于 2024-08-22 19:59:06 字数 424 浏览 9 评论 0原文

现在,我在尝试在自定义 SimpleCursorAdapter 中实现 FilterQueryProvider 时遇到了问题,因为我不确定在 FilterQueryProvider 的 runQuery 函数中要做什么。

换句话说,由于组成 ListView 的查询基本上从数据库表中获取 rowID、名称和第三列,因此我希望能够根据名称列的部分值来过滤游标。

但是,我不确定是否可以直接从 runQuery 执行此操作而不扩展我的数据库类,因为我想过滤现有游标,或者我是否必须在我的数据库类中创建一个新的查询函数来部分搜索我的名称列,并且如果是这样,我将如何在 runQuery 中使用 CharSequence 约束参数时创建查询语句?

我还担心与尝试基于部分文本运行多个查询相关的性能问题,因为相关数据库表大约有 1300-1400 行。换句话说,我在尝试过滤光标时会遇到瓶颈吗?

Right now, I'm running into issues trying to implement a FilterQueryProvider in my custom SimpleCursorAdapter, since I'm unsure of what to do in the FilterQueryProvider's runQuery function.

In other words, since the query that comprises my ListView basically gets the rowID, name, and a third column from my databases's table, I want to be able to filter the cursor based on the partial value of the name column.

However, I am uncertain of whether I can do this directly from runQuery without expanding my DB class since I want to filter the existing cursor, or will I have to create a new query function in my DB class that partially searches my name column, and if so, how would I go about creating the query statement while using the CharSequence constraint argument in runQuery?

I am also concerned about the performance issues associated with trying to run multiple queries based on partial text since the DB table in question has about 1300-1400 rows. In other words, would I run into a bottleneck trying to filter the cursor?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

守望孤独 2024-08-29 19:59:06

您需要运行一个查询,该查询将返回一个新的过滤游标:

public class MyActivity extends ListActivity implements FilterQueryProvider {

    private Cursor cursor;

    @Override
    public Cursor runQuery(CharSequence constraint) {
        if(cursor != null) {
            cursor.close();
        }
        cursor = somehowGetAFilteredCursorFor(constraint);
        startManagingCursor(cursor);
        return cursor;
    }

}

You need to run a query that will return a new filtered cursor:

public class MyActivity extends ListActivity implements FilterQueryProvider {

    private Cursor cursor;

    @Override
    public Cursor runQuery(CharSequence constraint) {
        if(cursor != null) {
            cursor.close();
        }
        cursor = somehowGetAFilteredCursorFor(constraint);
        startManagingCursor(cursor);
        return cursor;
    }

}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文