- @Override
- protectedvoid onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- final LinearLayout linearLayout=new LinearLayout(this);
- linearLayout.setOrientation(LinearLayout.VERTICAL);
- LinearLayout linearLayout1 =new LinearLayout(this);
- linearLayout1.setOrientation(LinearLayout.VERTICAL);
- Button button1= new Button(this);
- button1.setText("增加新项目");
- Button button2 = new Button(this);
- button2.setText("增加新组");
- linearLayout.addView(button1);
- linearLayout.addView(button2);
- //设定按钮单击监听器,动态增加控件.
- button2.setOnClickListener(new Button.OnClickListener(){
- publicvoid onClick(View v) {
- Context context = v.getContext();
- LinearLayout linearLayout2 =new LinearLayout(context);
- linearLayout2.setOrientation(LinearLayout.HORIZONTAL);
- EditText groupNameEditText =new EditText(context);
- //设置控件大小.
- groupNameEditText.setWidth(160);
- ImageButton imagebutton1 =new ImageButton(context);
- Button saveButton = new Button(context);
- Button exitButton = new Button(context);
- linearLayout2.addView(groupNameEditText);
- linearLayout2.addView(imagebutton1);
- linearLayout2.addView(saveButton);
- linearLayout2.addView(exitButton);
- linearLayout.addView(linearLayout2);
- }
- });
- setContentView(linearLayout);
- }