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

  • Home
  • SEARCH
  • 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 3871930
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T21:52:17+00:00 2026-05-19T21:52:17+00:00

What I have: A custom listview with a custom adapter, with a custom ListViewItem

  • 0

What I have: A custom listview with a custom adapter, with a custom ListViewItem (which extends LinearLayout)

What i want to do: When the listbox item is selected, I want to change the background drawable of the selected view.

What Happens: Currently nothing. The Toast does appear as it should, but the Background drawable does not change. I tried calling View.Invalidate() but that doesn’t seem to do anything either.

Here is the snippet of code that is supposed to change the drawable:

public void onItemClick(AdapterView<?> arg0, View view, int index, long arg3) 
{
    Card card = CardVM.GetCurrentCards().get(index);
    card.setBlocked(!card.isBlocked());
    if (card.isBlocked())
    {
        view.setBackgroundResource(R.drawable.bluegradient);
        Toast.makeText(this, "Card is now Blocked", 1).show();
    }
    else
    {
        view.setBackgroundResource(R.drawable.greengradient);
        Toast.makeText(this, "Card is now Available", 1).show();
    }
}

The toggle functionality does work, if you click on it the first time, it will say “card is now blocked”. The second time shows “Card is now available”… and so on. The setBackgroundResource simply does not work.

Also, when the list view is populated, the background colors are set correctly (using the same resources and the same function).

Thanks in advance.

UPDATE

It appears the background DOES change, but ONLY if the screen is forced to re-draw it. For example, when you click on the first item in the list to turn it blue, you need to scroll down (to get it off the screen) then scroll back up. THEN it turns blue. Can we avoid this somehow?

  • 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-19T21:52:17+00:00Added an answer on May 19, 2026 at 9:52 pm

    use AdapterView.OnItemSelectedListener() and maybe something like view.setBackgroundDrawable(getResources().getDrawable(R.drawable.listview_item_selected));

    Edit:

    invalidate the layout not the individual view.

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

Sidebar

Related Questions

I have a ListView with a custom Adapter that extends ArrayAdapter. It's a ArrayAdapter
I have a ListView powered by a custom adapter that dynamically changes the background
I have a custom ListView that uses a custom ArrayAdapter (which basically just overrides
I have implemented a custom list view which looks like the twitter timeline. adapter
I have a ListView backed by a custom adapter based on a CursorAdapter. The
I have got ListView with a custom Adapter. Every row contains clickable buttons and
I have a ListView that I'm populating from a custom ListAdapter . Inside the
I have a custom list adapter contains a layout with controls in it. I
I have a listview from an SQLDatabase using custom CursorAdaptor. I would like to
i have a list view and custom list adapter for it. There are various

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.