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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T03:08:00+00:00 2026-05-17T03:08:00+00:00

I have a ListView with a bunch of ListItem’s. When the user selects an

  • 0

I have a ListView with a bunch of ListItem’s. When the user selects an item, I would like to change that ListItem’s background to an image. How can I accomplish this?

listView.setOnItemClickListener(new OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> a, View v, int position, long id) {
    // how do I change the ListItem background here?
    }
});
  • 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-05-17T03:08:00+00:00Added an answer on May 17, 2026 at 3:08 am

    You can set that in the adapter of your ListView. What you have to do is use the setBackgroundResource on the View that you are returning. Let me give you a brief example:

    // lets suppose this is your adapter (which obviously has
    //to be a custom one which extends from on of the main
    //adapters BaseAdapter, CursorAdapter, ArrayAdapter, etc.)
    
    // every adapter has a getView method that you will have to overwrite
    // I guess you know what I'm talking about
    public View getView( args blah blah ){
        View theView;
        // do stuff with the view
    
        // before returning, set the background
        theView.setBackgroundResource(R.drawable.the_custom_background);
    
        return theView;
    }
    

    Notice that I’m using R.drawable.the_custom_background, which means that you have to write a little XML selector. Don’t worry, it’s easier than it sounds. You create an XML file called the_custom_background.xml inside the res/drawable folder:

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

    Notice again, I’m using @drawable/the_background_color, so finally create another drawable in the res/drawable folder called the_background_color:

    <?xml version="1.0" encoding="UTF-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
        <solid android:color="#FF0000" />
    </shape>
    

    I know it seems to be very messy, but this is the Android way. You could also try to modify the View inside the setOnItemClickListener, but I think that’s undesirable and harder to implement.

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

Sidebar

Related Questions

I have a ListView-derived class which creates a bunch of user controls that are
I have this SearchMenuActivity that has a bunch of options the user can select.
I have a form in which I display a bunch of image. I would
I have listview with some listadapter after click on item from list I'd like
I have ListView. I would like to fill each row of ListView with a
I have a listView that lists a bunch of files, and a set of
I have a listView displaying a bunch of graphs. I can sort this listview
I have a bunch of ListViews inside of a HorizontalScrollView. I would like to
I have listview item like below <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=match_parent android:layout_height=60dp android:orientation=horizontal android:descendantFocusability=blocksDescendants > <TextView
I have a ListView that displays a bunch of homework assignments. The ListView items

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.