I have a LinearLayout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="wrap_content"
style="@style/activated_item"/>
with style/activated_item:
<style name="activated_item" parent="android:Theme.Holo">
<item name="android:background">@drawable/item_light_list</item>
</style>
where drawable/items_light_list:
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:exitFadeDuration="@android:integer/config_mediumAnimTime">
<item android:state_activated="true" android:drawable="@drawable/list_activated_holo"></item>
<item android:state_selected="true" android:drawable="@drawable/list_selected_holo_light"></item>
<item android:drawable="@drawable/list_selected_holo_light"></item> <!-- If I would remove this line the item will be selected after a long click -->
</selector>
The mentioned LinearLayout is used for inflating in ‘view’ to be used as an item(s) in ListFragment. I need the android:background value to be changed after a longpress on the item. I tried to do:
public boolean onItemLongClick(AdapterView<?> parent, View view,
int position, long id) {
view.setSelected(true);
return true;
But this didn’t work.
Please advice what shall I do and how to change my drawable resourse in order to set a different background color after a longclick.
EDIT:
If I remove <item android:drawable="@drawable/list_selected_holo_light"></item> everything is working, but this is not a workaround for me.
Have you tried View.setBackgroundColor(int)?