【问题标题】:quick search within app in android?在android中的应用程序内快速搜索?
【发布时间】:2011-07-04 07:00:56
【问题描述】:

我的应用程序已经运行良好。我需要对其实施快速搜索功能。快速搜索我的意思是当用户输入我想要获取的每个字符时。我的活动是一个列表活动,其数据来自数据库查询。假设列表视图有 50 个项目,当用户使用单词作为“测试”进行搜索时,我想查询数据库并过滤项目并将其显示在同一个列表视图中。类似于 android 中的联系人搜索。请让我知道如何实现这一点。一个快速的样本将有助于充分。谢谢。

【问题讨论】:

    标签: android android-listview android-searchmanager


    【解决方案1】:

    【讨论】:

    • 我可以用这个进行搜索。但是,当用户键入文本时发生搜索的快速搜索并没有发生。如何添加该功能。感谢您的时间和帮助。
    【解决方案2】:

    我在之前的一个应用中实现了这个功能。整个代码太长,这里就不贴了。所以,我已经发布了它的一些部分。您可能会阅读一些关于我使用的方法的信息,并为您的应用程序完成它。

    EditText filterText;
    
    words = new MySimpleCursorAdapter(Main.this, R.layout.emptylist, temp, from, to);
    
            filterText= (EditText) findViewById(R.id.search_box);
            filterText.addTextChangedListener(filterTextWatcher);
    
    
            words.setFilterQueryProvider(new FilterQueryProvider() {
                @Override
                public Cursor runQuery(CharSequence constraint) {
                    Cursor cur=mDbHelper.fetchSugNotes(filterText.getText().toString());
                    return cur;
                }
            });
    
    
    private TextWatcher filterTextWatcher = new TextWatcher() {
    
        public void afterTextChanged(android.text.Editable s) {
    
        };
    
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {};
    
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            words.getFilter().filter(s.toString());
        };
    };
    

    【讨论】:

      猜你喜欢
      • 2010-09-12
      • 1970-01-01
      • 2011-05-11
      • 1970-01-01
      • 1970-01-01
      • 2013-04-26
      • 2022-01-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多