I want to make a list of ImageButtons in an Activity with three buttons in each row. If I make this with XML (considering there are over 100 buttons) eclipse complains that there are to many views.
Is there a better way to do this? Thanks!
I think you should make buttons dinamically.. like this
Button[] btnWord = new Button[num];
LinearLayout linear;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dynamicview);
test();
}
private void test() {
linear = (LinearLayout) findViewById(R.id.linear);
for (int i = 0; i < btnWord.length; i++) {
btnWord[i] = new Button(this);
btnWord[i].setHeight(50);
btnWord[i].setWidth(50);
btnWord[i].setTag(i);
btnWord[i].setOnClickListener(btnClicked);
linear.addView(btnWord[i]);
}
}
OnClickListener btnClicked = new OnClickListener() {
@Override
public void onClick(View v) {
Object tag = v.getTag();
Toast.makeText(getApplicationContext(), "clicked button", Toast.LENGTH_SHORT).show();
}
};
you can change the number of button array
Button[] btnword = new Button[num];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With