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.
在 java 文件中设置单选组时,当我尝试通过使用 setOnCheckedChanngeListener 方法时,它正在调用复合按钮,但我想要单选按钮。我该如何解决这个问题?
如果我理解您的问题,这就是解决方案:
CompoundButton您在侦听器方法中收到的是 a ,RadioButton因此您可以对其进行转换:
CompoundButton
RadioButton
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked){ RadioButton radioButton = (RadioButton)buttonView; ... }