Reputation: 56
I want to create a layout in Android in a java class. I need that the user introduce a number between 1 to 20 and this create the number of butttons that the user has chosen.
I know that this is possible in Java but I don't know if this is possible in Android, any idea?Thnaks!!
Upvotes: 0
Views: 106
Reputation: 2258
LinearLayout buttonsLayout = (LinearLayout)findViewById(R.id.buttons_layout);
LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
for(int i=0;i<numberOfButtons;i++){
Button button = new Button(this);
button.setText("Buttin "+(i+1));
button.set....other attributes
buttonsLayout.addView(button, layoutParams);
}
Upvotes: 1