Should I use setSelected
when onItemClick
when using setMultiChoiceModeListener
?
Asked
Active
Viewed 784 times
0
2 Answers
2
Won't change background color. Root element of list item is RelativeLayout (in my case)?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:attr/activatedBackgroundIndicator">
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#ebebeb"
android:dividerHeight="1dip"/>
</RelativeLayout>

Arnes
- 403
- 1
- 5
- 20
-
1It's Your LIST layout. You need to set that background parameter to root element of LIST ITEM layout which You inflating in Your adapter to every listView's row. – udenfox Apr 20 '15 at 07:08
-
If you are using a drawable selector to specify the color, set `android:background="@drawable/list_selector` on the list item layout and then in the selector `item` use `android:state_activated="true"` to identify the background color to use when the item is activated. – Soren Stoutner Jul 05 '16 at 03:21
1
No, You should not.
When You enter Multi Choice Mode
(usually it's triggered by long click on a list item) main onItemClick listener will be overriden and all items that will be pressed will be marked as selected.

udenfox
- 1,594
- 1
- 15
- 25
-
Ok. Thanks. But how to make color changes when listitem is selected? I've asked that question but nobody gave me an answer. – Arnes Apr 19 '15 at 19:55
-
-
@Arnes anyway. Simpliest way to do so: set android:background="?android:attr/activatedBackgroundIndicator" to root element of list item xml You use for Your listView. And I think that answer will be helpful for You: http://stackoverflow.com/a/16976534/3809678 – udenfox Apr 19 '15 at 20:03