2011-09-24 68 views
1

我有tableLayout與3個textView在TableRow中。 如何在數據庫中添加TextView中的新數據(1個textView = 1名稱)? 多數民衆贊成在不工作:如何從數據庫中添加TextView中的新數據(1個textView = 1名稱)?在一個循環

我的光標說:SELECT * FROM TABLE_NAME

Cursor cursor = database.query(TABLE_NAME, 
    new String[] {"*"}, 
null, null,null,null,"_id"); 



    cursor.moveToFirst(); 
     try { 
     if (!cursor.moveToFirst()) { 
      return; 
     } 

     do { 
      TextView textView = (TextView)findViewById(R.id.edit); 
      textView.setText(cursor.getString(0)); 
      } while (cursor.moveToNext()); 
    } finally { 
    cursor.close(); 
    } 

我的表:

 _id student 
     1 Said 
     2 Bill 
     3 John 

回答

0

您將要覆蓋TextView通過edit確定每次時間致電setText(String)。您可能需要以編程方式創建TextView的新實例。

TableRow row = new TableRow(context); 
do { 
    TextView textView = new TextView(context); 
    textView.setText(cursor.getString(0)); 
    row.addView(textView); //add each textview to your row 
} while (cursor.moveToNext()); 

myTableLayout.addView(row); //add your row to your table 

如果你已經有了一個TableLayout,你可以添加一個TableRow它使用addView(View v)來。將TextView的新實例添加到您的TableRow,您應該得到你想要的。

+0

謝謝!!!!!!!!!! –

相關問題