安卓 : At a time only one item isChecked in listview with checkboxes

标签 android listview checkbox

我有一个自定义 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/

相关文章:

android - 在 ListView 中滚动时切换按钮更改状态

javascript - JS 或 Jquery : how to add an "option" to a checkbox

android - 在 Android 回收器 View 中以编程方式左右对齐 View

android - setContentview() 在 onConfigurationChanged() 中更改布局但不在 android 中设置数据

android - 列表未在 android 中显示

c# - 如何从 ListView 中拉取一种类型的项目

javascript - 如何在 typescript 中设置复选框属性

复选框勾选值绑定(bind)

android - 单击联系人图标后,将自己的应用程序图标添加到 QuickAction Dialog

java - 在 Sqlite 中使用 where 子句更新查询