【发布时间】:2014-07-27 00:00:40
【问题描述】:
这让我发疯了。我有一个ListView 和一个ArrayList 作为我的适配器。 ListView 模式为CHOICE_MODE_MULTIPLE,布局为simple_list_item_checked。我现在可以在我的ListView 中选择多个项目。
我的情况:
int length = jsonList.size();
SparseBooleanArray checked = lv_Devices.getCheckedItemPositions();
for (int i = 0; i <length ; i++ ){
if (checked.get(i)) {
onList.add(jsonList.get(i));
jsonList.remove(i);
lv_Devices.setItemChecked(i, false);
length--;
}
}
adapter.notifyDataSetChanged();
adapterOn.notifyDataSetChanged();
这里是 LogCat:
size of array 8 : contains [1, 2, 3, 4, 5, 6, 7, 8]
you removed index 0
[2, 3, 4, 5, 6, 7, 8]
you removed index 1
[2, 4, 5, 6, 7, 8]
you removed index 2
[2, 4, 6, 7, 8]
you removed index 3
[2, 4, 6, 8]
从最终结果可以看出,数组正在移动索引。我试图实现的目标:获取每个选定的项目并将它们添加到另一个 ListView,同时从当前的 ListView 中删除。
LogCat 显示当我选择所有项目时会发生什么。这也发生在单击按钮时。对此的任何建议都是完美的。这也是我第一次使用stackoverflow。我并没有真正使用它,因为这里已经讨论了大多数编程错误。我在这个问题上遇到了困难。
【问题讨论】:
标签: java android listview android-listview arraylist