开发者

How to create Array of buttons in android using java

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜