我一直在努力弄清楚如何做到这一点。我想启动我的CActivity
,我想要一个滚动的TableLayout来填充(想想滚动Instagram的Feed)。我想为我的TableRow设计XML并动态填充这些对象。目前我的唯一对象是content
。如何动态创建TableRows并填充其对象?
我真的很难引用TableRow中的对象。
<RelativeLayout
tools:context="com.....CActivity">
<ScrollView
android:id="@+id/scrollView"
<TableLayout
...
android:id="@+id/CTableLayout">
<TableRow
...
android:id="@+id/CTableRow">
<TextView
...
android:id="@+id/content" />
</TableRow>
</TableLayout>
</ScrollView>
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_c);
this.data_array = new blahblah[]{a,b,c};
TableLayout tl =(TableLayout)findViewById(R.id.CTableLayout);
for(int i = 0; i < this.data_array.length; i ++){
TableRow tr = new TableRow(this);
TableRow row = (TableRow)inflater.inflate(R.id.CTableRow, null);
TextView content = (TextView)row.findViewById(R.id.content);
content("IS THIS CONTENT");
tr.addView(content);
tr.setPadding(0,10,0,10);
tl.addView(tr);
}
}
由于