Deselect selected item in ListView

Ron picture Ron · Jul 19, 2013 · Viewed 25.7k times · Source

I use a ListView in my layout like this:

 <ListView android:id="@+id/list"
              android:layout_width="fill_parent"
              android:layout_gravity="center"
              android:layout_height="match_parent"
              android:layout_weight="0.7"
              android:layout_marginTop="5dp"
              android:orientation="vertical"
              android:layout_centerInParent="true"
              android:divider="@color/dark_grey"
              android:drawSelectorOnTop="false"
              android:focusable="true"
              android:layout_marginBottom="55dp"
              android:cacheColorHint="#00000000"
              android:listSelector="@color/light_grey"
              android:dividerHeight="1px" />

The selector works great but how can I disable the selector?

I tried:

listView.clearChoices();
listView.setSelected();
listView.setSelector();
...

and a few more things but nothing works. Any ideas how I can turn my selected item back to normal? Can't be that complicated, right?

Edit: I need a programmatical solution!

Thanks!

Answer

M-WaJeEh picture M-WaJeEh · Jul 22, 2013

Call requestLayout() on the ListView after clearChoices(). It will work.