【发布时间】:2013-10-14 06:17:41
【问题描述】:
我需要一个可以选中和取消选中的单选按钮。
但是从我对堆栈溢出的读数来看,单选按钮将在选中后保持选中状态,因为需要选择 on 选项?
到目前为止,这是我的代码:
RadioButton rButton = new RadioButton(getActivity());
rButton.setText(listItems.get(i));
rButton.setId(i);
rButton.setChecked(false);
rButton.setClickable(true);
// rButton.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View v) {
// RadioButton rButton = (RadioButton)
// layout.findViewById(position);
// rButton.setChecked(!rButton.isChecked());
// }
// });
layout.addView(rButton);
即使使用注释掉的 onclick 侦听器,它也可以工作。
如何取消选中单选按钮?
【问题讨论】:
-
单选按钮只需要检查集合中的一个即可。
-
单选按钮在单选按钮组中(否则没有任何意义),单选按钮组使用
clear方法来删除选择。 -
(RadioButton) layout.findViewById(position);我不知道position是什么,但我怀疑它是radioButton的id
标签: android radio-button radio-group