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 8865705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:34:57+00:00 2026-06-14T16:34:57+00:00

My question is this: Is it possible to apply a drawable resource to a

  • 0

My question is this:
Is it possible to apply a drawable resource to a TextView in a ListView, that makes it keep its background color, after the user lifts his/her finger ofF said TextView?

Consider:

  1. The user selects an item in a ListView
  2. The list item highlights
  3. The user removes his/her finger off the item
  4. The item is no longer highlighted

My question is, is it possible to make allow the object to remain highlighted at step 4 ?
Im currently using a state list drawable for my list items.
I’ve tried

android:state_focused="true"

android:state_selected="true"

android:state_check="true"

Thanks in advance 🙂

Edit

Solved. I achieved this through java code. For those interested, I did the following:

Declared an integer variable, ‘previous’, to store the previous index, starting at 0 for the first item, and force highlighted it through setBackground().

Then, in the onItemClickListener for the list, I simply clear the highlight of the previous item, highlight the current, and set ‘previous’ to the index of the currently selected item.

Don’t know how I didn’t think of this before xD I’m usually good at problem solving.

Happens to all of us at some point i guess 😛

  • 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-14T16:34:58+00:00Added an answer on June 14, 2026 at 4:34 pm

    Although your approach would work, it’s extra pieces of code which I would like to avoid. The steps to achieve this are as follows:

    Make the list view’s selection mode to singleChoiceMode.

    Make this selector

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
    
        <item android:drawable="@color/color_light_blue_for_selected_item" android:state_checked="true"/>
    
    </selector>
    

    Set this as the background of your list items.

    And it should work.

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

Sidebar

Related Questions

It's possible that this question has already been asked, but I can't seem to
Following this question, it seems that it is possible to open a file from
After reading the answer to this question , I learned that SFINAE can be
Is it possible to apply an extension method to an interface? (C# question) That
Follow-up to this question: Setting background-color of select options in JQuery I have a
In answers to this question , I learned that it is not possible to
Possible Duplicate: Apply different background color using jquery I have three divs on a
It this possible? How? (Maybe silly question, but I couldn't find answer :( )
This question is a bit open ended as I'm not sure it's possible or
This question was asked quite some time ago, and while it covers possible solutions

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.