开发者

How to create Array of buttons in android using java

开发者 https://www.devze.com 2023-03-13 22:01 出处:网络
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.

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.

Rega开发者_高级运维rds

Anshuman


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消