icecreamman
icecreamman

Reputation: 611

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

Upvotes: 8

Views: 5014

Answers (5)

Tom Ongchangco
Tom Ongchangco

Reputation: 1

I use this method to clear a ListView selection:
listView.SelectedItem = null;

Upvotes: 0

Holger
Holger

Reputation: 502

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.

Upvotes: 3

Asterius
Asterius

Reputation: 2200

Use listView.setItemChecked(-1, true);

Upvotes: 0

Lumis
Lumis

Reputation: 21639

The simpliest way I could find is to refresh the adapter the ListView is using:

listAdapter.notifyDataSetChanged();

ListView will then refresh, having the same choices but the selection highlight will be cleared.

Upvotes: 0

Harsh Dev Chandel
Harsh Dev Chandel

Reputation: 763

Ok what i could do for this set the selection color and background both of the same color if possible or set selection with full alpha value that makes it transparent and even if selection is there it wont be visible anymore

Upvotes: 0

Related Questions