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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:24:36+00:00 2026-05-23T13:24:36+00:00

I have an unusual issue with my ListView . I currently have a deselectAll()

  • 0

I have an unusual issue with my ListView. I currently have a “deselectAll()” method which iterates through the items in my ListView and sets them to unchecked (the items implement the Checkable interface). The “checked” variable gets changed correctly (the view reports as not being checked), but the visual indicator (in this case, a background change) does not show the view as unchecked (the background stays the color of a checked item).

I am iterating and deselecting through my listview like so (I also added my declerations):

private ListView vw_entryList;

private void deselectAll() {
    for (int i = 0; i < sAdapter.getCount(); i++) {
        ((Entry)vw_entryList.getItemAtPosition(i)).setChecked(false);
    }
}

The code for my implemented setChecked() is as follows:

public void setChecked(boolean checked) {
    _checked = checked;
    if (checked) {
        setBackgroundResource(R.drawable.listview_checked);
    }
    else  {
        setBackgroundResource(R.drawable.listview_unchecked);
    }
    invalidate();
}

It should be noted that when the items are clicked, they are toggled between checked and unchecked in the OnItemClickListener, and this works ok, with the background change and everything. The code for toggling is very similar:

public void toggle() {
    _checked = !_checked;
    setBackgroundResource(_checked ? 
            R.drawable.listview_checked : R.drawable.listview_unchecked);
    invalidate();
}

The only difference I can see is where the methods are called from. toggle() is called from within the OnItemClickListener.onClick() method, while my deselectAll() is called from within a button’s standard OnClickListener, both in the same class. Does anyone have any ideas as to why the background doesn’t change when I call my deselectAll() function?

  • 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-23T13:24:37+00:00Added an answer on May 23, 2026 at 1:24 pm

    After trying everything (thanks for your help Jarek), I found a solution that works for my purposes. Instead of implicitly calling the setChecked() within the view that was clicked, I leave it up to the setItemChecked() method within the ListView class.

    My updated code:

    private void deselectAll() {        
        for (int i = 0; i < sAdapter.getCount(); i++) {
            vw_entryList.setItemChecked(i, false);
        }
    }
    

    My best guess is that the ListView knows that its items implement the Checkable class, and thus requires itself to be the handler of all item operations. Something along those lines. If anyone can explain in more detail why this solution works while the others did not, I’ll reward them with the answer and an upvote.

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

Sidebar

Related Questions

I'm trying to shred XML files that have an unusual layout, because items are
Have deployed numerous report parts which reference the same view however one of them
I am running into an unusual issue with assembly loading. Let's say we have
I have a very unusual issue; I have a few ToggleButtons inside of a
I have an unusual issue and I can't figure out why: I have the
I have an unusual CSS issue in IE7. Here's my html and css code:
I have an unusual project that I need to display large sets of questions
This is a rather unusual question but here's the issue: I have a WPF
I have an unusual SQL table (not mine) which has the following fields (among
I have little unusual problem to solve. I need some hint or links to

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.