1
我想创建layout
以不同的类编程,而不是activity
,所以我将从Activity调用一个函数,并且所有用于创建布局的代码都在函数中。所以请给我一些想法来编写代码。在另一个类中进行活动布局
这是我的活动:
public class Main extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TableLayout tl = (TableLayout) findViewById(R.id.table1);
testing t1 = new testing();
Main m = new Main();
t1.makelayout(tl,m);
}
}
这是我的类,它具有的功能是编程生成布局:
public class testing {
public void makelayout(TableLayout tl,Main m1) {
// TODO Auto-generated method stub
//Main m = new Main();
TextView tv= new TextView(m1);
tv.setText("hello1");
tl.addView(tv);
}
}
我能做到这一点还是不请帮助我。