【发布时间】:2013-01-07 14:48:50
【问题描述】:
我有一个 Android 应用程序。我在其中有 ListView。列表视图由 ArrayAdapter 和布局文件构成。 在布局文件中,我有复选框。所以我想通过按下按钮查看是否所有复选框都被选中。我怎么能做到这些? 更新:我想看看哪些复选框被选中
【问题讨论】:
标签: android android-listview android-activity
我有一个 Android 应用程序。我在其中有 ListView。列表视图由 ArrayAdapter 和布局文件构成。 在布局文件中,我有复选框。所以我想通过按下按钮查看是否所有复选框都被选中。我怎么能做到这些? 更新:我想看看哪些复选框被选中
【问题讨论】:
标签: android android-listview android-activity
您可以通过代码获取列表中已检查项目的数量:
private int getChecked()
{
SparseBooleanArray checked = yourList.getCheckedItemPositions();
return checked.size();
}
编辑: 要检查是否检查了每个项目:
private boolean isEveryChecked()
{
SparseBooleanArray checked = yourList.getCheckedItemPositions();
return checked.size()==yourList.getCount();
}
yourList 是 ListView。
【讨论】: