Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android ListView Remove Selection

Is there a way to elegantly remove the selection on a ListView. It would act in the opposite manner of ListView#setSelection(int position). I would like to programmatically remove the selection from the ListView (such that no item is selected). It does not appear the API has an easy way to do it. Any thoughts?

My question is similar to: Android: disable ListView selection

like image 304
icecreamman Avatar asked Nov 09 '11 19:11

icecreamman


1 Answers

None of the other answers worked for me so I did this:

    SparseBooleanArray positions = getListView().getCheckedItemPositions();
    for (int i = 0; i < positions.size(); i++) {
        getListView().setItemChecked(positions.keyAt(i), false);
    }

Not very elegant but it works.

like image 65
Holger Avatar answered Nov 10 '22 14:11

Holger