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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With