3

I want to create an array of buttons in my app. So how that can be done. Secondly, is it possible to interact with each button in an array of buttons? If so, how? Please suggest to me.

Regards
Anshuman

2
  • 7
    Give us an example of what you've got so far. We're not your personal code monkeys. Commented Jun 20, 2011 at 9:38
  • 2
    Yeah, that's possible. Good luck! Commented Jun 20, 2011 at 9:40

1 Answer 1

3

Inside you Activity do something like this:

    LinearLayout linear = new LinearLayout(this);
    linear.setOrientation(LinearLayout.VERTICAL);       

    ArrayList<Button> ab = new ArrayList<Button>();
    for (Button b : ab) {       
        linear.addView(b);
        b.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

            }
        });
    };
    setContentView(linear);
Sign up to request clarification or add additional context in comments.

1 Comment

If you want to find each button then give also an ID to each one. To later use findViewById.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.