Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7724071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:36:12+00:00 2026-06-01T04:36:12+00:00

I am using multiple choice ListView items. The user can select multiple items. So

  • 0

I am using multiple choice ListView items. The user can select multiple items. So I wanted to highlight the items selected by the user by changing either the text color or background color of the list row. I have gone through stack overflows links but didn’t get the proper solution. When I am trying to do it, it is randomly changing any unselected item background color. Help!!!

public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
    videocursor.moveToPosition(position);
    v.setBackgroundColor(Color.parseColor("#80B7DBE8"));
    SaveSelections();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T04:36:13+00:00Added an answer on June 1, 2026 at 4:36 am

    Far better than the above suggestions is to use a selector, also known as a state-list drawable. That way, the OS takes care of all of the business of color highlighting, etc.

    more explicitly, take the following xml and save it under res/drawable as something like li_background.xml (I’m using images, but feel free to swap out colors as is appropriate to your situation)

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android" >
            <item android:state_focused="true"
              android:drawable="@drawable/list_item_pressed" />
        <item android:state_pressed="true"
              android:drawable="@drawable/list_item_pressed" />
        <item android:state_selected="true"
              android:state_activated="true"
              android:drawable="@drawable/list_item_selected" />
        <item android:state_activated="true"
              android:drawable="@drawable/list_item_selected" />
        <item android:state_selected="true"
              android:drawable="@android:color/black" />
        <item android:drawable="@android:color/transparent" />
    </selector>
    

    and set the background of All ListItems in the ListView to R.drawable.li_background. if your listView is properly configured for multiple selections (android:choiceMode="multipleChoice" or listView.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE); if you prefer) then android will take care of the rest. This stuff isn’t well documented, I had a hard time finding the solution and I see similar questions all the time, but the relevant dos are here and here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using multiple choice listview,in this I would am getting the position values
It's my first Andoid app. I can't implement a multiple choise in my ListView(i
I want to save the state of a multiple choice listview checkbox's. I have
I have list of items with check boxes using this code: ProcessList = (ListView)
In my multiple choice Quiz show project on google app engine multiple users can
I have a django form that allows a user to select multiple options: CARDS
I'm using the ListView to provide a list for the user to choose from.
I am using multiple instances of AVAudioPlayer to play multiple audio files simultaneously. I
I am using multiple threads in my application using while(true) loop and now i
I'm using multiple threads in my application. Basically I have a combo box and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.