更新时间:2023-12-06 15:10:04
我看到你在这里做的错误
I see the error u r doing here
LinearLayout mainLayout = (LinearLayout) findViewById(R.layout.main);
您将布局作为 Linearlayout 对象,您应该将 LinearLayout id 设为
You r taking the layout as Linearlayout object, you should take the LinearLayout id
试试这个
LinearLayout lnr = (LinearLayout) findViewById(R.id.LinearLayout01);
Button b1 = new Button(this);
b1.setText("Btn");
lnr.addView(b1);