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.
精彩评论