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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:02:03+00:00 2026-06-16T20:02:03+00:00

Because my listView/List items have checkboxes I have the problem, that checkboxes are checked

  • 0

Because my listView/List items have checkboxes I have the problem, that checkboxes are checked or unchecked when I’m scrolling through the list. Therefore I need to track checked items in a ArrayList for example. So I added an OnCheckedChangeListener on each checkbox and I’ve added the listener in the “getView” from the custom adapter for the listview.

Now since every checbox react on the click I have the following problem.

@Override
public View getView(int position, View convertView, ViewGroup parent) {    
...
cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                if (!MainActivity.getSharedInstance().getIsCheckedArray().contains(tasks.get(MainActivity.ID)))
                    MainActivity.getSharedInstance().getIsCheckedArray().add(tasks.get(MainActivity.ID));
                for (String i : MainActivity.getSharedInstance().getIsCheckedArray()) {
                    Log.i("RUN", i);
                }
            } else {
                if (MainActivity.getSharedInstance().getIsCheckedArray().contains(tasks.get(MainActivity.ID)))
                    MainActivity.getSharedInstance().getIsCheckedArray().remove(tasks.get(MainActivity.ID));
                for (String i : MainActivity.getSharedInstance().getIsCheckedArray()) {
                    Log.i("RUN", i);
                }
            }
        }
    });

From each list item I have an own ID and I can reach the item with that ID. But when I click on the checkboxes to get the ID, I only get the ID of one item ( the last item ). When I click on the other checkboxes they react to the change but I only get the ID from the last item and not from the items before the last one.

Do I overwrite the listeners when I always create the new Listener?

Update:
Nevermind, I added this to the onCheckChangeListener

String curIndex = tasks.get(MainActivity.ID);

and it worked

  • 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-16T20:02:04+00:00Added an answer on June 16, 2026 at 8:02 pm

    I Think your mistake is, that You doesn´t use a LayoutInflater. Just try:

        LayoutInflater inflater =  (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.yourListViewItemLayout, parent,false);
    
        final Checkbox yourCheckBox = (CheckBox)view.findViewById(R.id.yourCheckBoxId);
                 yourCheckBox.setOnCheckedChangeListener......
    

    this should work

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

Sidebar

Related Questions

I have a ListView bound to a Generic List collection. I need to be
In my app, I have a listview that it's items consist of an image,
I posting this again, trying to make the question/problem clearer: ListView lv; List<Item> items;
I have a ListView, checkboxes = true, View = List. On the start of
I'm displaying a list of items in a WPF ListView, the items have a
I have learned that when using android:entries with a ListView , it uses android.R.layout.simple_list_item_1
I've got a ListView and, for View = List, would like to have the
I have a form which has a ListView and buttons to add/edit/delete items from
I have a ListView, and I want to make a background that scrolls with
I have achieved something similar for particular items within my ListView in this question.

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.