【问题标题】:How to search data using searchview?如何使用 searchview 搜索数据?
【发布时间】:2014-10-16 11:48:02
【问题描述】:
public Cursor searchByInputText(String inputText) throws SQLException {

    String query = "SELECT tag as _id," +
            TABLE_CONTACTS +  " from " + TABLE_CONTACTS +
            " where " + TABLE_CONTACTS + " MATCH '" + inputText + "';";
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor Cursor = db.rawQuery(query,null);

    if (Cursor != null) {
        Cursor.moveToFirst();
    }
    return Cursor;

}

我试过上面的代码,但我无法搜索。

我正在尝试获取存储在我的数据库中的任何标签字段数据,一旦我在搜索框中进行搜索,它就不会显示我的数据库中的任何数据。

【问题讨论】:

    标签: android xml sqlite searchview


    【解决方案1】:

    尝试使用 SearchView 的setOnQueryTextListener

    类似的东西:

    new SearchView.OnQueryTextListener( ) {
        @Override
        public boolean   onQueryTextChange( String newText ) {
            // this is called when text changes in SearchView 
            textView.setText(newText);
        }
    
        @Override
        public boolean   onQueryTextSubmit(String query) {
            // this is called when Search Button is clicked
            textView.setText(query);
        }
    }
    

    【讨论】:

    • 我没有得到...如果我搜索标签存储在数据库(sq lite)中的任何标签都应该显示搜索列表...
    猜你喜欢
    • 2022-06-21
    • 2015-04-26
    • 1970-01-01
    • 2014-11-12
    • 1970-01-01
    • 1970-01-01
    • 2017-08-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多