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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:54:23+00:00 2026-06-16T01:54:23+00:00

I am developing a simple Android app which creates a ListView with a checkbox

  • 0

I am developing a simple Android app which creates a ListView with a checkbox as follows

listAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_multiple_choice,results);
this.setListAdapter(listAdapter);
ListView lv = getListView();
lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);

lv.setOnItemClickListener(new OnItemClickListener(){
    @Override
     public void onItemClick(AdapterView<?> parent, View view, int position,
                        long id) {
           CheckedTextView check = (CheckedTextView)view;
           //The below code needed for running on AVD version 4.2
           if(check.isChecked()) { 
                   // Checkbox checked do something 
            } 
           else { 
                    // Not checked. Do something 
            }
            /* Exact opposite need on Samsung phone running 2.3.6
            if(!check.isChecked()) {
                      // Checkbox checked do something
            }
            else {
             // Not checked. DO something
            } */

This is truly weird. How will the app ever be compatible with both version when they require completely opposite checks?

Please let me know how I can handle this. Any help will be appreciated.

  • 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-16T01:54:24+00:00Added an answer on June 16, 2026 at 1:54 am

    i know the problem, on newer frameworks the onItemClick call before the checkd attribute of the checkbox changed!

    i check the checked state of my checkboxes in after item clicking (e.g. on activity close or save button click).

    look at list.getCheckedItemPositions()… it will return a SparseBooleanArray you can use!

    EDIT: example

    public class MyMultiChoiceActivity extends Activity implements View.OnClickListener {
    
        private ListView list = null;
        private boolean savedSelectionInvalid = true;
        private List<Integer> selectedIds = new ArrayList<Integer>();
    
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            this.setContentView(R.layout.entry_data_multi_choice_filter);
    
            //initialize the list
            list = (ListView) findViewById(R.id.list);
            listAdapter = new MyListAdapterClass(this, R.layout.list_item_multiple_choice);
            list.setAdapter(listAdapter);
    
            //onclick on a item, set the selectaion as invalid
            list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                    savedSelectionInvalid = true;
                }
            });
    
            list.setAdapter(listAdapter);
    
            //...
        }
    
        //...
    
        private void validateChecked() {
            if(savedSelectionInvalid == true) {
                SparseBooleanArray checkedItemlist = list.getCheckedItemPositions();
                selectedIds.clear();
                for (int i=0; i < checkedItemlist.size(); i++){
    
                    if (checkedItemlist.valueAt(i)) {
                        selectedIds.add(a.keyAt(i));
                    }
                }
                this.savedSelectionInvalid = false;
            }
        }
    
        //...
    
        //this method se
        private void saveAndClose() {
            validateChecked();
    
            //now you have the selectedIds filled with every checked item key!
    
            this.finish();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to Android, I am developing a simple and small app, which
I am developing a simple sip-based voip app for android. I used this sample
I'm new at android developing. I'm trying to make a simple drumset app, when
I am developing a simple android app.In that i want to store a string
I'm new to android developing, so i apologise if this is a simple/noob-ish question,
I'm developing a simple camera app which is based on the android developers tutorial
HELP please this is just a simple android app I am developing, it's meant
I am currently developing socket communication between android and server, which is a simple
I am developing an android app which requires search functionality. My app contains action
Just starting out on android developing. To start off, I'm building an app which

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.