新手 请教布局问题。
如果一个布局 通过XML读取以后,还能对这个布局进行更改么。。。。
如下代码报错:
- Java code
protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); TableLayout tb = (TableLayout)findViewById(R.layout.selectcontact); TableRow mtb = new TableRow(this); Button button = new Button(this); button.setText("DynamicButton"); mtb.addView(button); tb.addView(mtb); this.setContentView(tb); }
如果全代码的话没有问题。请问是XML文件读取后不能更改么 还是我的代码有问题?请赐教 新手 。。。
[解决办法]
try
- Java code
protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); this.setContentView(R.layout.selectcontact); TableLayout tb = (TableLayout)findViewById(R.layout.selectcontact); TableRow mtb = new TableRow(this); Button button = new Button(this); button.setText("DynamicButton"); mtb.addView(button); tb.addView(mtb); }