gpt4 book ai didi

java - 创建特定数量的按钮

转载 作者:行者123 更新时间:2023-12-01 13:21:32 25 4
gpt4 key购买 nike

我想在 Android 中的 java 类中创建布局。我需要用户输入 1 到 20 之间的数字,这将创建用户选择的按钮数量。

我知道这在 Java 中是可能的,但我不知道这在 Android 中是否可能,有什么想法吗?Thnaks!

最佳答案

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);
}

关于java - 创建特定数量的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21991942/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com