2014-10-16 184 views
-2
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; 

} 

我試過上面的代碼,但我無法搜索。如何使用searchview搜索數據?

我試圖獲取標記字段數據,無論存儲在我的數據庫中,一旦我在搜索框中搜索它不顯示我的數據庫中的任何數據。

回答

0

嘗試使用搜索查看的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); 
    } 
} 
+0

OK,我會嘗試這個... – 2014-10-16 11:56:17

+0

我沒有得到......如果我搜索任何標籤存儲在數據庫中的標籤(SQ lite)應顯示搜索列表... – 2014-10-16 12:44:12

相關問題