动态创建TextView(或者其他view),能否使用在布局中已经存在的一个Textview的
样式
或者说能不能克隆布局中已经存在的textview
直接ViewRoot里面获取一个TextView,
再设置TextView newTextView = 获取的TextView
这样是否可行
楼上的方法只是给原来的TextView增加了一条引用.
LinearLayout x = (LinearLayout) findViewById(R.id.container);
for (int i = 0; i < 5; i++) {
View c = LayoutInflater.from(this).inflate(R.layout.singlerow, x);
TextView t = ((TextView)c.findViewById(R.id.textView1));
t.setId(i+10000);
t.setText("text"+i);
}
TextView b = (TextView) findViewById(10003);
b.setText("10003");
可以使用LayoutInflater.from(this).inflate(resource, root)来创建TextView