2016-12-05 159 views
-4

我是Android的初學者,我現在不知道如何從方法DBHelper類填充listview具有相同的方法處理靜態查詢,我需要從editext進行查詢插入值dinnamyc請求插入值。從SQLite數據庫的列表視圖中檢索數據

public void SrchDB(View v) { 
    ListView p = (ListView) mDBHelper.findProduct(EdtxPoliza.getText().toString()); 
    if (p == null) 
    { 
     Toast.makeText(this, "No Match Found!",Toast.LENGTH_LONG).show(); 
     return; 
    } 
} 
+0

我高度懷疑你希望'findProduct'返回一個ListView對象。也許你是爲了Arraylist?在任何情況下,您都不應該查看CursorAdapter類的文檔。 –

回答

0

首先

修改您mDBHelper.findProduct(String);返回Collection,說ArrayList<String>

public ArrayList<String> findProduct(String vString){ 
    SQLiteDatabase db = getReadableDatabase(); 
    ArrayList<String> myRes = new ArrayList<>(); 
    Cursor cursor = db.rawQuery("YOUR_QUERY", null); 
    while (cursor.moveToNext()){ 
     myRes.add(cursor.getString(0)); //change the index to your column index in table. 
    } 
    return myRes; 
} 

創建適配器

ListAdapter myListAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,ResultOf_findProduct); 

一套適配器yourListView

yourListView.setAdapter(myListAdapter); 

就是它,希望它會幫助你。

+0

感謝您的幫助iSandeep 已經解決了 – EDenebd

+0

@EDenebd如果這是一個正確的答案,然後標記它。 – iSandeep

相關問題