【问题标题】:How to retrive info from all checkboxes if they have same id?如果它们具有相同的ID,如何从所有复选框中检索信息?
【发布时间】:2013-01-07 14:48:50
【问题描述】:

我有一个 Android 应用程序。我在其中有 ListView。列表视图由 ArrayAdapter 和布局文件构成。 在布局文件中,我有复选框。所以我想通过按下按钮查看是否所有复选框都被选中。我怎么能做到这些? 更新:我想看看哪些复选框被选中

【问题讨论】:

标签: android android-listview android-activity


【解决方案1】:

您可以通过代码获取列表中已检查项目的数量:

private int getChecked()
{
    SparseBooleanArray checked = yourList.getCheckedItemPositions();

    return checked.size();
}

编辑: 要检查是否检查了每个项目:

private boolean isEveryChecked()
{
     SparseBooleanArray checked = yourList.getCheckedItemPositions();

     return checked.size()==yourList.getCount();
}

yourListListView

【讨论】:

    猜你喜欢
    • 2015-11-11
    • 2017-06-19
    • 1970-01-01
    • 2010-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-06
    相关资源
    最近更新 更多