首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网络技术 > 网络基础 >

新手 请问布局有关问题

2012-02-10 
新手 请教布局问题。如果一个布局 通过XML读取以后,还能对这个布局进行更改么。。。。如下代码报错:Java codepr

新手 请教布局问题。
如果一个布局 通过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);    } 

热点排行