如何使使用可编程的方式XML一个TableLayout? [英] How to make a TableLayout from XML using programmable way?
本文介绍了如何使使用可编程的方式XML一个TableLayout?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想TableLayout从国土资源(XML)采用可编程的方式添加到的LinearLayout。
I am trying to add TableLayout to the LinearLayout from resourse(xml) using programmable way.
的补充TableLayout数量是动态的。这将是1之间 - 10。 我认为这是更好的方式从资源XML做到这一点。由于设计不破。
The added TableLayout count is dynamic. It would be between 1 - 10. I think it is better way to make it from resource xml. Because design doesn't break.
如何制作的?
其实我不知道如何从XML创建一个新的实例。
Actually I don't know how to create a new instance from the XML.
请帮忙。你们。
在此先感谢。
推荐答案
事情是这样的:
TableLayout table = (TableLayout)findViewById(R.id.table);
LayoutInflater inflater = getLayoutInflater();
for(int i = 0; i < 10; i++) {
TableRow row = (TableRow)inflater.inflate(R.id.table_row,
table, false);
TextView text = (TextView)row.findViewById(R.id.text);
text.setText("row: " + i);
// other customizations to the row
table.addView(row);
}
在哪里table_row.xml看起来是这样的:
Where table_row.xml looks something like this:
<TableRow xmlns:android="http://schemas.android.com/apk/res/android">
<TextView android:id="@+id/text" />
<TextView android:id="@+id/text2" />
</TableRow>
这样,您仍然可以创建XML中的表行,并有行数是动态的。
This way you can still create the table row in XML, and have the number of rows be dynamic.
这篇关于如何使使用可编程的方式XML一个TableLayout?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文