在Android搜索活动中使用Filterable

时间:2015-07-07 10:40:17

标签: android simplecursoradapter android-filterable

我在结果方面没有任何区别,而在我在可搜索的视图中输入时应该对它们进行过滤。这是我的代码请帮忙。此代码运行但不过滤任何内容。

       public boolean onQueryTextChange(String newText) {

            String sql="select history,rowid _id from search_history order by counter desc limit 5";
             final Cursor cursor = db.findCursor(sql,null);
            //TextView tv=(TextView) findViewById(R.id.textView123);
            if (cursor != null && cursor.moveToFirst()) {
                 int[] columnTextId = new int[] {R.id.textView1};
                 SuggestionSimpleCursorAdapter simple = new SuggestionSimpleCursorAdapter(getBaseContext(),
                        R.layout.text_view_for_suggestions, cursor,
                            columns , columnTextId
                            , 1);

                 simple.getFilter().filter(newText.toString());
                 simple.notifyDataSetChanged();
                    simple.setFilterQueryProvider(new FilterQueryProvider() {

                        @Override
                        public Cursor runQuery(CharSequence constraint) {
                            // TODO Auto-generated method stub
                            Log.v("Running","Yes");
                            return db.findCursor("select history,rowid _id from search_history", null);
                        }
                    });
                    searchView.setSuggestionsAdapter(simple);

            }
            return true;
        }
    });

[解决] UPDATE:

        @Override
                        public Cursor runQuery(CharSequence constraint) {
                            // TODO Auto-generated method stub
                            Log.v("Running","Yes");
                            String x=constraint.toString();
                            return db.findCursor("select history,rowid _id from search_history where history LIKE '"+x+"%'", null);
                        }
                    });

0 个答案:

没有答案