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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:07:19+00:00 2026-06-04T13:07:19+00:00

I am using ExpandableListView, and the child row each has a textview, and checkbox

  • 0

I am using ExpandableListView, and the child row each has a textview, and checkbox within it.

What I want to do is, when a user pushes a button, the activity figures out which items are ‘checked’ and do something with those items.

I read many posts on how ExpandableListView and checkboxes currently don’t work well, and how I need to keep an additional data structure to keep track of what’s has been selected, and not. This post covers that issue:
ExpandableListView and checkboxes

Done! I now can keep track of what’s been selected, and what’s not been selected.

Now I want to tackle the problem of check boxes not showing their states. I have noticed that the check boxes change randomly when:

  • screen rotation changes
  • a group collapses/opens

I know that it’s possible to detect these events.

I want to know if there’s a way to set the check boxes by hand. I initially tried

ExpandableListView elv = getExpandableListView();
for(int i = 0; i < elv.getChildCount(); i++) {
  CheckBox checkbox = ... somehow get checbox within the list
  checkbox.setChecked(checkList.at(i, j));
}

where i, and j indicate which group, and children, and checkList keeps track of checked/unchecked items.

However, I noticed that value of getChildCount() depends on how many groups are open, and does not necessarily tell me which list item I can manipulate.

ExpandableListView has been used, and someone must have had a way of getting around this issue. Is there a smart solution to this? Specifically, I am looking for ways to check/uncheck appropriate items in the list at onGroupExpand and onConfigurationChange (or similar events.)

Thank you in advance!

  • 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-04T13:07:20+00:00Added an answer on June 4, 2026 at 1:07 pm

    Check following sample Expandable list adapter

    /**
         * A simple adapter which maintains an ArrayList of photo resource Ids. 
         * Each photo is displayed as an image. This adapter supports clearing the
         * list of photos and adding a new photo.
         *
         */
        public class MyExpandableListAdapter extends BaseExpandableListAdapter {
    
    
            // Sample data set.  children[i] contains the children (String[]) for groups[i].
            private String[] groups = { "People Names", "Dog Names", "Cat Names", "Fish Names" };
            private String[][] children = {
                    { "Arnold", "Barry", "Chuck", "David" },
                    { "Ace", "Bandit", "Cha-Cha", "Deuce" },
                    { "Fluffy", "Snuggles" },
                    { "Goldy", "Bubbles" }
            };
    
            private ArrayList<ArrayList<Boolean>> checkboxStatus = new ArrayList<ArrayList<Boolean>>();
    
            public MyExpandableListAdapter() {
                int groupCount = groups.length;
                for(int i=0; i<groupCount; i++) 
                {
                    int childCount = children[i].length;
                    ArrayList<Boolean> childStatus = new ArrayList<Boolean>();
                    for(int j=0; j<childCount; j++) {
                        childStatus.add(false);
                    }
                    checkboxStatus.add(childStatus);
                }
            }
    
            public Object getChild(int groupPosition, int childPosition) {
                return children[groupPosition][childPosition];
            }
    
            public long getChildId(int groupPosition, int childPosition) {
                return childPosition;
            }
    
            public int getChildrenCount(int groupPosition) {
                return children[groupPosition].length;
            }
    
            public TextView getGenericView() {
    
                // Layout parameters for the ExpandableListView
                AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
                        ViewGroup.LayoutParams.MATCH_PARENT, 64);
    
                TextView textView = new TextView(ExpandableListCheckboxActivity.this);
                textView.setLayoutParams(lp);
                // Center the text vertically
                textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
                // Set the text starting position
                textView.setPadding(36, 0, 0, 0);
                return textView;
            }
    
            public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
                    View convertView, ViewGroup parent) {
    
                CheckBox chkbox = new CheckBox(ExpandableListCheckboxActivity.this);
                chkbox.setTag("" + groupPosition + "," + childPosition);
                chkbox.setOnCheckedChangeListener(checkboxListener);
                chkbox.setText(children[groupPosition][childPosition]);
    
                chkbox.setChecked(checkboxStatus.get(groupPosition).get(childPosition));
    
                return chkbox;
            }
    
            public Object getGroup(int groupPosition) {
                return groups[groupPosition];
            }
    
            public int getGroupCount() {
                return groups.length;
            }
    
            public long getGroupId(int groupPosition) {
                return groupPosition;
            }
    
            public View getGroupView(int groupPosition, boolean isExpanded, View convertView,
                    ViewGroup parent) {
                TextView textView = getGenericView();
                textView.setText(getGroup(groupPosition).toString());
    
                return textView;
            }
    
            public boolean isChildSelectable(int groupPosition, int childPosition) {
                return true;
            }
    
            public boolean hasStableIds() {
                return true;
            }
    
            private OnCheckedChangeListener checkboxListener = new OnCheckedChangeListener() {
    
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    String positions = buttonView.getTag().toString();
                    int groupPosition = Integer.valueOf(positions.split(",")[0]);
                    int childPosition = Integer.valueOf(positions.split(",")[1]);
                    checkboxStatus.get(groupPosition).set(childPosition, isChecked);
                }
            };
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using an ExpandableListView in which each group is a TextView and each
Using Yii, I want to delete all the rows that are not from today.
I'm using ExpandableListView with a SimpleCursorTreeAdapter. Is it possible to get the group number
I need to get item's index(position) knowing its ID while using ExpandableListView. Is there
I'm working on a project that has an ExpandableListView nested inside a regular ListView
Using Android TelephonyManager an application can obtain the state of data activity over the
Using php/html, I want to retrieve email addresses (plus other information) from MySQL and
Using the WPF Grid control is easy when your child elements are always contained
using xmltextreader, how would I load a hashtable. XML: <base><user name=john>2342343</user><user name=mark>239099393</user></base> This was
Hi i am displaying items according to different categories using Expandable Listview.Now I want

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.