开发者

Define multiple buttons

Is there a way to define 31 buttons in one action.. Something like this :

    B开发者_JS百科utton but[] = new Button[31];
 for(int i=1;i<32;i++)
 {
     but[i] = (Button) findViewById(R.id.Button0+i ---? );

 }


ViewGroup parent = (ViewGroup)findViewById(R.id.PARENT_ID_HERE);
Button but[] = new Button[31];
for(int i=1;i<32;i++)
{
    but[i] = new Button(this);
    // set listeners and stuff
    parent.addView(but[i]);
}


In your ways is to define buttons in layout file. You can define buttons in java activity file by addview method to add buttos to its' parent view.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜