gpt4 book ai didi

android - 我可以在其中动态创建带有 RadioButtons 的 RadioGroup(没有 xml)吗?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:41:11 25 4
gpt4 key购买 nike

我想在 onCreate 函数中创建 RadioGroup,其中包含 RadioButton 列表。我想不使用 xml 布局来做练习。可能吗?谢谢。

最佳答案

像这样:

....
RadioGroup group = new RadioGroup(this);
group.setOrientation(RadioGroup.HORIZONTAL);
RadioButton btn1 = new RadioButton(this);
btn1.setText("BTN1");
group.addView(btn1);
RadioButton btn2 = new RadioButton(this);
group.addView(btn2);
btn2.setText("BTN2");
....
RadioButton btnN = new RadioButton(this);
group.addView(btnN);
btnN.setText("BTNN");
yourLayout.addView(group);
....

关于android - 我可以在其中动态创建带有 RadioButtons 的 RadioGroup(没有 xml)吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9861563/

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