简体   繁体   中英

How to get Background Color of currently selected item from ListView in Android

Can anyone tell me how to get background color of selected item from ListView in android? Here I an using ListView with multiple item select mode and I just want to set background color of selected items. If user unchecked the option I want to restore it's background color to black.

I can set the background color of selected items but I am not getting the current background color of selected item.

Please help me.

I am using Android 4.0.3 and editor Eclipse

for this you should maintain a boolean variable for each item initially with false and when you click on any item you should make the variable to true.

and in getView() of your custom adapter you check whether it is true or false and do the needfull.

before trying this have a xml file in drawable folder and set it as background if this doesn't work then do the above must work..

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- touch down -->
    <item
        android:drawable="@drawable/list_selector_pressed"
        android:state_pressed="true"/>
    <!-- selected -->
    <item
        android:drawable="@drawable/list_selector_selected"
        android:state_selected="true"
        android:state_focused="false"
        android:state_pressed="false"/>
</selector>

Refer this LINK LINK

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM