Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有 3 个单选组,共有 9 个单选按钮。我将它们分组,因为我想让它们在布局中很好地对齐。但是,我想限制用户只能从这 9 个单选按钮中选择 1 个,作为一个完整的初学者,我想知道如何操作。非常感谢。
在 Activity 的 Java 文件中,通过调用 获取所有单选按钮(RadioButton)findViewById(R.id.my_radio_button),并在每个单选按钮上设置一个侦听器,以取消选择所有其他单选按钮。理想情况下,您可以遍历这些单选按钮的列表,而不是编写 9 个单独的匿名内部类。
(RadioButton)findViewById(R.id.my_radio_button)