Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
521 views
in Technique[技术] by (71.8m points)

android - Deselect selected item in ListView

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...