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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:49:23+00:00 2026-05-19T17:49:23+00:00

I’m working with an Expandable List, like this: The Expandable list activity has a

  • 0

I’m working with an Expandable List, like this:
alt text

The Expandable list activity has a method called “OnGroupExpand” which allows you to perform some work before the parent expands and it’s children are exposed.

In my case, I want to attach a checkChangeHandler to each child’s checkbox so that when it’s clicked, I can mark the child as complete. I have the list showing up and the children show when the parent expands, but my check box does nothing.

Then, I try to add checkbox handlers dynamically in the “onGroupExpand” method. However, when onGroupExpand is triggered I get an illegal cast exception when trying to get a reference to each child view.

public void  onGroupExpand (int groupPosition) {

      int numOfChildren = expListAdapter.getChildrenCount(groupPosition);


            for(int i = 0; i < numOfChildren; i++)
            {
                 //Get exception here because getChild() returns Object - but how else can
                 //can I attach a check box to each child?
                 View v = (View) expListAdapter.getChild(groupPosition, i);


                 CheckBox cb = (CheckBox)v.findViewById( R.id.checkComplete ); 
                 cb.setOnCheckedChangeListener(new OnCheckedChangeListener(){
                    public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
                        Toast.makeText(getBaseContext(), "Check Changed for " + groupPosition, 2000);
                    }
                  });
             }

My primary question is about getting a reference to the Child view so that I can attach a handler dynamically. Please see the code comment where I’m trying to do this.
Thanks for your time…

  • 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-19T17:49:24+00:00Added an answer on May 19, 2026 at 5:49 pm

    I believe the problem is that the

    View v = (View) expListAdapter.getChild(groupPosition, i);
    

    Doesn’t return a View but is returning the data for that position. You might be using strings or a prefs object or something else. You will get your underlying object for it, you can make changes to that object. When the view is created in the method below (and this is called automatically by the ListView), you can setup any onCheckChanged listeners:

    abstract View    getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent)
    

    Adding example code

    Here is the example Adapter that does what you wanted to do. The Views are created on the Adapter and not the Activity. I assume you are creating a SimpleExpandableListAdapter in your Activity. Instead of that, add the following class and create that view.

    import java.util.List;
    
    import android.content.Context;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.CheckBox;
    import android.widget.CompoundButton;
    import android.widget.SimpleExpandableListAdapter;
    import android.widget.Toast;
    import android.widget.CompoundButton.OnCheckedChangeListener;
    
    public class ExampleAdapter extends SimpleExpandableListAdapter {
    
        protected Context mContext;
    
        public ExampleAdapter(ExampleActivity exampleActivity, List createGroupList, int groupRow, String[] strings, int[] is, List createChildList, int childRow, String[] strings2, int[] is2) {
            super(exampleActivity, createGroupList, groupRow, strings, is, createChildList, childRow, strings2, is2);
            mContext = exampleActivity;
        }
    
        @Override
        public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
            View v = super.getChildView(groupPosition, childPosition, isLastChild, convertView, parent);
    
            if (v != null) {
                final String value = "Check Changed for " + groupPosition + " " + childPosition;
                CheckBox cb = (CheckBox)v.findViewById( R.id.checkComplete ); 
                cb.setOnCheckedChangeListener(new OnCheckedChangeListener(){
                   public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
                       Toast toast = Toast.makeText(mContext, value, 2000);
                       toast.show();
                   }
                 });
            }
    
            return v;
        }    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I am trying to loop through a bunch of documents I have to put
I'm making a simple page using Google Maps API 3. My first. One marker
I have a bunch of posts stored in text files formatted in yaml/textile (from
We're building an app, our first using Rails 3, and we're having to build

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.