Android 如何使用searchview搜索数据?
我尝试了上面的代码,但我无法搜索 我正在尝试获取存储在数据库中的标记字段数据,一旦我在搜索框中搜索,它将不会显示数据库中的任何数据。尝试使用SearchView 诸如此类:Android 如何使用searchview搜索数据?,android,xml,sqlite,searchview,Android,Xml,Sqlite,Searchview,我尝试了上面的代码,但我无法搜索 我正在尝试获取存储在数据库中的标记字段数据,一旦我在搜索框中搜索,它将不会显示数据库中的任何数据。尝试使用SearchView 诸如此类: public Cursor searchByInputText(String inputText) throws SQLException { String query = "SELECT tag as _id," + TABLE_CONTACTS + " from " + TABLE_C
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;
}
我没有得到…如果我搜索标签任何标签存储在数据库(sq lite)应该显示搜索列表。。。
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);
}
}