0
我的代碼編程方式將行添加到表問題在添加行代碼 - 通過沒有例外,但沒有代碼顯示
TableLayout tl = (TableLayout) findViewById(R.id.tblLog);
List<String> s=new LinkedList<String>();
s.add("test1");
s.add("test2");
s.add("test3");
// Go through each item in the array
int id=0;
for (String temp:s)
{
id++;
// Create a TablView v = new View(this);eRow and give it an ID
TableRow tr = new TableRow(currentActivity);
TableLayout.LayoutParams tableRowParams=
new TableLayout.LayoutParams
(TableLayout.LayoutParams.FILL_PARENT,TableLayout.LayoutParams.WRAP_CONTENT);
int leftMargin=10;
int topMargin=2;
int rightMargin=10;
int bottomMargin=2;
tableRowParams.setMargins(leftMargin, topMargin, rightMargin, bottomMargin);
tr.setLayoutParams(tableRowParams);
// Create a TextView to house the name of the province
TextView labelTV = new TextView(currentActivity);
labelTV.setId(200+id);
labelTV.setText(temp);
labelTV.setTextColor(Color.RED);
labelTV.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
tr.addView(labelTV);
tl.addView(tr, new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
}
,我有XML
<TableLayout
android:id="@+id/tblLog"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
</TableLayout>
,我通過功能無一例外地,我已經調試過,但沒有在屏幕上顯示。有人能告訴我我做錯了什麼嗎?