2012-08-09 57 views
0

我從數據庫創建了選項卡及其內容。現在我需要幫助瞭解如何從這些控件獲取用戶輸入的值 - 如何獲取選項卡上的控件列表(以便可以保存數據)。下面是我如何填充選項卡內容的濃縮樣品:從動態內容獲取控件/視圖選項卡

public View createTabContent(String tag) 
{ 
SQLiteDatabase db2 = openOrCreateDatabase(msDbFile, MODE_PRIVATE, null); 
Cursor cList = db2.rawQuery("SELECT * FROM CheckList WHERE CatID=" + tag, null); 
TableLayout tl = new TableLayout(FormChecklist.this); 
tl.setBackgroundColor(new Color().WHITE); 
while(cList.moveToNext()) 
{ 
    /* Create a new row to be added. */ 
    TableRow tr = new TableRow(FormChecklist.this); 
    tr.setLayoutParams(new LayoutParams(
       LayoutParams.FILL_PARENT, 
       LayoutParams.WRAP_CONTENT)); 

    /* Create the row-content. */ 
    TextView lblQuestion = new TextView(FormChecklist.this); 
    lblQuestion.setText(cList.getString(2)); 
    lblQuestion.setTag(tag); 
    /* Add control to row. */ 
    tr.addView(lblQuestion); 

    CheckBox chkCompleted = new CheckBox(FormChecklist.this); 
    chkCompleted.setText("Completed"); 
    chkCompleted.setLayoutParams(new LayoutParams(
       LayoutParams.FILL_PARENT, 
       LayoutParams.WRAP_CONTENT)); 
    chkCompleted.setTag(tag); 
    /* Add control to row. */ 
    tr.addView(chkCompleted); 

    /* Add row to TableLayout. */ 
    tl.addView(tr,new TableLayout.LayoutParams(
    LayoutParams.FILL_PARENT, 
    LayoutParams.WRAP_CONTENT)); 
} 
db2.close(); 
return tl; 
} 

回答

0

沒有回覆,但終於想通了,希望有人會發現這個信息很有幫助。我保存例行我遍歷控制

tl.setId(1000 + miTlCnt); 

然後在像這樣: 方法我真是修改我createTabContent增加一個ID爲TableLayout

for (int i = 1000 + miTlCnt; i > 1000; i--) 
{ 
    TableLayout tl = (TableLayout)findViewById(i); 
    if (tl != null) 
    { 
     for (int j = 0; j < tl.getChildCount(); j++) 
     { 
      TableRow row = (TableRow)tl.getChildAt(j); 
      CheckBox chkCompleted = (CheckBox)row.getChildAt(1); 
     } 
    } 
}