Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class AndroidWalkthroughApp1 extends Activity implements View.OnClickListener {
- final int TOP_ID = 3;
- final int BOTTOM_ID = 4;
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- RelativeLayout top = new RelativeLayout(this);
- top.setId(TOP_ID);
- RelativeLayout bottom = new RelativeLayout(this);
- bottom.setId(BOTTOM_ID);
- for (int i = 0; i < 2; i++) {
- Button button = new Button(this);
- button.setText("Button " + i);
- button.setId(i);
- button.setOnClickListener(this);
- add generated button to view
- if (i == 0) {
- top.addView(button);
- } else {
- bottom.addView(button);
- }
- }
- RelativeLayout root = (RelativeLayout) findViewById(R.id.root_layout);
- LinearLayout root = (LinearLayout) this.findViewById(R.id.root_layout);
- root.addView(top);
- root.addView(bottom);
- }
- @Override
- public void onClick(View v) {
- Toast toast = Toast.makeText(AndroidWalkthroughApp1.this, "You clicked button " + v.getId(), Toast.LENGTH_LONG);
- toast.show();
- RelativeLayout parentLayout = (RelativeLayout) v.getParent();
- parentLayout.removeView(v);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement