【发布时间】:2011-08-04 17:40:34
【问题描述】:
我有对象数组列表,我需要在运行时将这些对象列表绑定到 TableLayout,但我没有将任何数据放入其中,请检查我的代码:
XML 代码:
<TableLayout android:background="#cfe1edFF" android:id="@+id/tl"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TableRow>
<TextView android:text="Symbol"
android:layout_height="fill_parent" android:textColor="#104e8b"
android:layout_width="wrap_content"
android:layout_weight="1" android:gravity="center" android:background="@drawable/shapefile"/>
<TextView android:text="A/c Type"
android:layout_height="fill_parent" android:textColor="#104e8b"
android:layout_width="wrap_content"
android:layout_weight="1" android:gravity="center" android:background="@drawable/shapefile">
</TextView>
<TextView android:text="Position" android:textColor="#104e8b" android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:layout_weight="1" android:gravity="center" android:background="@drawable/shapefile">
</TextView>
</TableRow>
<ScrollView>
<TableLayout android:id="@+id/score_table"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableRow></TableRow>
</TableLayout>
</ScrollView>
</TableLayout>
所以从上面的 TableLayout "score_table" 我试图绑定来自 ArrayList 对象的数据,例如:
使用 arryalist 对象绑定表格布局的代码:
public void TableBinding(ArrayList<Position> posLst)
{
TableLayout tLayout=(TableLayout)findViewById(R.id.score_table);
Position pos;
for(int i=0;i<posLst.size();i++)
{
TableRow tr = new TableRow(this);
tr.setId(100+i);
pos=posLst.get(i);
tr.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
TextView b = new TextView(this);
b.setText(pos.Symbol);
tr.addView(b);
//b.setId(200+i);
TextView b1 = new TextView(this);
b1.setText(pos.AcType);
tr.addView(b1);
//b1.setId(300+i);
TextView b2 = new TextView(this);
b2.setText(pos.Position);
tr.addView(b2);
//b2.setId(400+i);
/* Add row to TableLayout. */
tLayout.addView(tr,new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
}
}
但是我没有得到任何数据,我已经检查了 ArrayList 获取数据,请帮助我。
谢谢, 唠叨。
【问题讨论】:
标签: android arraylist tablelayout