【发布时间】:2015-04-30 23:30:14
【问题描述】:
我有一个使用 listview 的 android 应用程序。每一行由 ImageView、一个 TextView 和一个 CheckBox 组成。 我想从此列表视图中获取选定的项目。我使用过
private void getSelectedItems() {
List<String>list = new ArrayList<String>();
try {
SparseBooleanArray checkedItems = new SparseBooleanArray();
checkedItems = listView.getCheckedItemPositions();
if (checkedItems == null) {
return;
}
final int checkedItemsCount = checkedItems.size();
for (int i = 0; i < checkedItemsCount; ++i) {
int position = checkedItems.keyAt(i);
boolean bool = checkedItems.valueAt(position);
if (bool) {
list.add(mainList.get(position));
}
}
} catch (Exception e) {
}
}
但是我想在启动时将某些项目设置为相对于某个条件已选中。只有当用户选中/取消选中某个项目时才会获得选中的项目。即使项目在以编程方式启动。这里有什么问题?
提前致谢
【问题讨论】: