2011-09-26 64 views
0

我下載這個數據庫腳本,我不知道我怎樣才能將其轉換成一個項目,而不是添加到列表視圖..其一個非常容易理解的數據庫代碼..數據庫添加項目到列表視圖?

http://www.anotherandroidblog.com/wp-content/uploads/2010/08/AABDatabase.zip

多數民衆贊成在它的源代碼..

也即時猜測它可能在這裏?

/** 
* retrieves a row from the database with the id number in the corresponding 
* user entry field 
*/ 
private void retrieveRow() 
{ 
    try 
    { 
     // The ArrayList that holds the row data 
     ArrayList<Object> row; 
     // ask the database manager to retrieve the row with the given rowID 
     row = db.getRowAsArray(Long.parseLong(updateIDField.getText().toString())); 

     // update the form fields to hold the retrieved data 
     updateTextFieldOne.setText((String)row.get(1)); 
     updateTextFieldTwo.setText((String)row.get(2)); 
    } 
    catch (Exception e) 
    { 
     Log.e("Retrieve Error", e.toString()); 
     e.printStackTrace(); 
    } 
} 

回答

1

若要從數據庫中添加項目到ListView,你可以有一個ArrayList

1)ArrayList<String> arrList = new ArrayList<String>();

2)獲取從數據庫項目,將它們添加到ArrayList的

 if(c.getCount() > 0){ 
      c.moveToFirst(); 
      for (int i = 0; i < c.getCount() - 1; i++) { 
       arrList.add(c.getString(0)); 
       c.moveToNext(); 
      } 

3.)Then populate the Adapter with the ArrayList(arrList).

4.)And fill the ListView with the Adapter.

+0

我不太明白..你可以給我一個代碼的修改版本 –

+1

你最好看看一些ListView的例子,然後嘗試填充我已經回答的。謝謝。 –