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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:15:15+00:00 2026-05-26T08:15:15+00:00

My app is currently targeted at Android 1.6. It contains a ListView with CHOICE_MODE_SINGLE

  • 0

My app is currently targeted at Android 1.6. It contains a ListView with CHOICE_MODE_SINGLE. All the items implement Checkable. I am using setItemChecked(int position, boolean value) to check/uncheck items as needed. It works as expected on Android 2.1, 2.2 and 2.3. On Android 1.6 however, no item gets checked.

Code looks like this:

Integer checkedIndex = 0; // This is actually set from somewhere else.

void updateCheckedItem() {
  int count = adapter.getCount();
  for (int i = 0; i < count; i++) {
    listView.setItemChecked(i, isChecked(i));
  }

  // Here, we should have a checked item (unless checkedIndex was null)
  SparseBooleanArray checkedPositions = listView.getCheckedItemPositions();
  int size = checkedPositions.size();
  // On Android 1.6, size is 0 (wrong)
  // On Android 2.x, size is 1 (correct)

  // Another try...
  int checkedPosition = listView.getCheckedItemPosition();
  // On Android 1.6, checkedPosition is INVALID_POSITION (-1), meaning nothing is checked (wrong)
  // On Android 2.x, checkedPosition is whatever checkedIndex is (correct)
}

boolean isChecked(int position) {
  return checkedIndex != null && checkedIndex == position;
}

This question resolved the problem by setting ListView’s ChoideMode in code, not XML. I did that in code to begin with and putting it in XML made no difference for me. Problem still occurs.

How can I make this work on Android 1.6?

  • 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-26T08:15:16+00:00Added an answer on May 26, 2026 at 8:15 am

    Found the problem. There was a change in setItemChecked() between 1.6 and 2.1.

    1.6 would always clear the checked items when setItemChecked() was called with value false. So unless the last item was the checked one, it would end up with a cleared array, hence no checked items.

    It can be circumvented by only calling setItemChecked for the checked item. Unchecking the other items is (obviously) handled by the ListView. If no item is to be checked (checkedIndex is null), we should use clearChoices() to make sure nothing is checked. That is useful in cases where the checked item was removed from the list and another item takes the position. If we don’t clear the choice, the ListView would check that position although checkedIndex is null.

    void updateCheckedItem() {
      if (checkedIndex != null) {
        listView.setItemChecked(selected, true);
      } else {
        listView.clearChoices();
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a web app and currently using sql server 2008 for it. But,
I currently have an app on the market that supports Android 1.5 (SDK level
I'm working on a Titanium app (currently targeted for iPhone deployment, but ultimately intended
I am currently developing an app targeted for the HP IPAQ 210. Part of
Our web app currently under development has authentication on all the pages. We can
I currently have a application targeted at android 2.3 (api level 10), but went
In my app currently I'm using #if DEBUG Console.WriteLine(....) #endif In a number of
I'm currently working on a C# app targeted for Windows Mobile 6 devices that
My android app currently has two layouts for its splash screen, portrait and landscape.
The way my app currently deals with orientation is it repositions all of the

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.