0

I'm trying to make a ListView simple list multiple choice, but when I choose for example the items number 1 and 3, the returned values will be number 1 and 2, if I choose any 5 random choices the returned values will be the first five values.

SparseBooleanArray checked = modeList.getCheckedItemPositions();
for (int i = 0; i < checked.size(); i++) {
        if (checked.valueAt(i) == true) {
            String tag = (String) modeList.getItemAtPosition(i);
            checkedItems.add(tag);
        }
}

And as I said, no matter what I choose the values will always return the first items of the list even if the choices are randomly selected.

4

1 回答 1

1

SparseBooleanArray is bit tricky. You should use construction like this:

SparseBooleanArray checked= listView.getCheckedItemPositions();
for (int i = 0; i <= checked.size(); i++) {
     if (checked.valueAt(i)) 
        yourListAdapterArray[checked.keyAt(i)];
}

Also, there is no need for that:

if (checked.valueAt(i) == true)

Better use simple:

if (checked.valueAt(i))
于 2013-05-09T20:10:10.257 回答