我有一个自定义 ListView
,每行包含 checkbox
和 `TextView'。我想将其设置为一次只能选中一个复选框.... 提前致谢。
最佳答案
如果你正在使用这个默认类
mAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_multiple_choice, mData);
然后你可以使用
setChoiceMode(ListView.CHOICE_MODE_SINGLE);
或者如果您正在使用任何自定义类,则按如下方式设置。
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
holder.mCheckBox = (CheckBox) convertView.findViewById(R.id.checkBox1);
holder.mCheckBox.setTag(position);
holder.mCheckBox
.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
// do your stuff here.
}
});
这将允许您只单击单个复选框,
关于安卓 : At a time only one item isChecked in listview with checkboxes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22141546/