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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:16:32+00:00 2026-06-15T10:16:32+00:00

When I tap a checkbox inside a ListView, a second item in the list

  • 0

When I tap a checkbox inside a ListView, a second item in the list becomes also checked. As example, if I check the 1st item, the 7th in the list becomes checked. Here is my code for the cell’s layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/relativeLayout1" android:layout_width="fill_parent"    android:layout_height="fill_parent"    xmlns:android="http://schemas.android.com/apk/res/android">

    <ImageView 
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content" 
        android:id="@+id/imgDisclosureIndicator" 
        android:src="@drawable/disclosureon" 
        android:layout_alignParentTop="true" 
        android:layout_alignParentRight="true" 
        android:paddingRight="6dp"></ImageView>

    <ImageView
        android:id="@+id/imgTaskState"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:src="@drawable/taskok" />

    <CheckBox
        android:id="@+id/chkTaskImage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/imgTaskState"
        android:layout_toLeftOf="@+id/imgDisclosureIndicator"
        android:layout_toRightOf="@+id/imgTaskState"
        android:focusable="false" />

</RelativeLayout>

I joined an image to help you out:

Checkbox problem

As a side note, the ListView is inside a ListFragment.

EDIT: Below is the code that maps my cell with its data.

String[] from = {"taskId", "taskStateId", "taskText", "disclosureIndicatorId"};
                    int[] to = {0, R.id.imgTaskState, R.id.chkTaskImage, R.id.imgDisclosureIndicator};
SimpleAdapter adapter = new SimpleAdapter(mContext, mList, R.layout.task_cell, from, to);
setListAdapter(adapter);

EDIT #2: This situation doesn’t happens if the ListView is shown vertically.

ListView problem

EDIT #3 : Even if I’m using a SimpleAdapter, with the following code, when the ListView is horizontal I’m getting the same error.

private class CellInspectionAdapter extends BaseAdapter
    {
            private Vector<InspectionCell> cells;
            private Context context;

            public CellInspectionAdapter(Context context, Vector<InspectionCell> cells)
            {
                this.cells = cells;
                this.context = context;
        }

        @Override
        public int getCount()
        {
            return this.cells.size();
        }

        @Override
        public Object getItem(int position)
        {
            return null;
        }

        @Override
        public long getItemId(int position)
        {
            return 0;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent)
        {
            // Map data from the ArrayList from the adapter
            LayoutInflater inflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

            View celluleTask;

            if (convertView == null) 
            {
                celluleTask = new View(context);
                celluleTask = inflater.inflate(R.layout.laprise_task_cell, null);

                // Assign data to the cell
                ImageView imgEtat = (ImageView)celluleTask.findViewById(R.id.imgTaskState);
                imgEtat.setImageResource(cells.get(position).getStateDrawable());

                // Assign text
                CheckBox chkCell = (CheckBox)celluleTask.findViewById(R.id.chkTaskImage);
                chkCell.setText(cells.get(position).getTexte());

                // Disclosure
                ImageView imgDisclosure = (ImageView)celluleTask.findViewById(R.id.imgDisclosureIndicator);
                imgDisclosure.setImageResource(cells.get(position).getDisclosureDrawable());    
            }
            else
            {
                celluleTask = (View)convertView;
            }

            return celluleTask;
        }
    }

EDIT #5: Here is the solution! Override the getViewTypeCount() and getItemViewType(int position) methods. I’ve added these lines to the SimpleAdapter and it works.

@Override
public int getViewTypeCount() {                 

    return getCount();
}

@Override
public int getItemViewType(int position) {

    return position;
}
  • 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-15T10:16:33+00:00Added an answer on June 15, 2026 at 10:16 am

    You’re using convertView incorrectly. A non-null convertView only spares you the creation of a new View and doing the layout stuff, but you have to set the contents of all the children of the convertView to match the current item. That also explains why it works in vertical because then both rows are visible simultanously.

    Try this:

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            // Map data from the ArrayList from the adapter
            LayoutInflater inflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    
            View celluleTask = convertView;
    
            if (celluleTask == null) {
                celluleTask = inflater.inflate(R.layout.laprise_task_cell, null);
            }
    
            // Assign data to the cell ALWAYS!
            ImageView imgEtat = (ImageView)celluleTask.findViewById(R.id.imgTaskState);
            imgEtat.setImageResource(cells.get(position).getStateDrawable());
    
            // Assign text
            CheckBox chkCell = (CheckBox)celluleTask.findViewById(R.id.chkTaskImage);
            chkCell.setText(cells.get(position).getTexte());
    
            // Disclosure
            ImageView imgDisclosure = (ImageView)celluleTask.findViewById(R.id.imgDisclosureIndicator);
            imgDisclosure.setImageResource(cells.get(position).getDisclosureDrawable());    
    
            return celluleTask;
    }
    

    P.S.: You also should move the fetching of the layout inflater out of the getView method so it has not to be done over and over again.

    P.P.S.: To avoid calling findViewById again and again, have a look at the View Holder Pattern.

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

Sidebar

Related Questions

Currently I have a UITextView field with the CheckBox Detect Links checked. The contents
I want to tap a control on the screen and have the ListView scroll
There is double tap to zoom / pinch to zoom ImageView (ImageViewTouch) from here
We can tap a NavigationItem in a rect that larger than the item rect
I tap a tab bar item, which triggers poptoRootViewControllerAnimated. Most of the time it
When I tap and hold and move my list around, it moves, but when
whenever I make a tap action on a UIWebView, for example clicking a link,
Ok Guys, here's the situation I have. I'm using a UITableViewController with Core Data.
I have attached 3 tap gesture recognizers to the same view - single, double
when my tap gesture fires I need to send an additional argument along with

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.