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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:56:41+00:00 2026-05-31T21:56:41+00:00

How do i set a OnCheckedChangeListener on each childelements checkbox? I can’t figure it

  • 0

How do i set a OnCheckedChangeListener on each childelements checkbox?
I can’t figure it out. When i check a checkbox i want a Toast popping up , telling me which child i have checked 🙂

Source:

public class ExpandableActivity extends ExpandableListActivity {

private String[] alphabet = { "a", "b", "c", "d", "e", "f", "g" };
private String c;

ArrayList<ArrayList<Integer>> check_states = new ArrayList<ArrayList<Integer>>();

private Context context;

@SuppressWarnings("unchecked")
@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    // Create an array of Strings, that will be put to our ListActivity
    setContentView(R.layout.expandablelist);

    Bundle extras = getIntent().getExtras();

    c = extras.getString("category");

    SimpleExpandableListAdapter expListAdapter = new SimpleExpandableListAdapter(
            this, createGroupList(), // Creating group List.
            R.layout.group_row, // Group item layout XML.
            new String[] { "Group Item" }, // the key of group item.
            new int[] { R.id.row_name }, // ID of each group item.-Data
                                            // under the key goes into
                                            // this TextView.
            createChildList(), // childData describes second-level
                                // entries.
            R.layout.child_row, // Layout for sub-level entries(second
                                // level).
            new String[] { "Sub Item" }, // Keys in childData maps to
                                            // display.
            new int[] { R.id.grp_child } // Data under the keys above go
                                            // into these TextViews.
    );
    setListAdapter(expListAdapter); // setting the adapter in the list.

}


@SuppressWarnings({ "rawtypes", "unchecked" })
private List createGroupList() {
    ArrayList result = new ArrayList();
    for (String s : alphabet) { // 15 groups........

        HashMap m = new HashMap();

        if (getResources().getIdentifier(c + s + "_name", "string",
                "dk.android.houseenabler") != 0) {
            int id = getResources().getIdentifier(c + s + "_name",
                    "string", "dk.android.houseenabler");
            getResources().getText(id);
            m.put("Group Item", getResources().getText(id)); // the key and
                                                                // it's
                                                                // value.

        } else {
            return result;
        }
        result.add(m);
    }
    return result;
}

@SuppressWarnings({ "rawtypes", "unchecked" })
private List createChildList() {

    ArrayList<ArrayList> result = new ArrayList<ArrayList>();
    for (String s : alphabet) {
        if (getResources().getIdentifier(c + s + "_name", "string",
                "dk.android.houseenabler") != 0) {
            int id = getResources().getIdentifier(c + s, "array",
                    "dk.android.houseenabler");

            String[] Rchilds = getResources().getStringArray(id);
            ArrayList<HashMap> secList = new ArrayList<HashMap>();
            for (String d : Rchilds) {
                HashMap childs = new HashMap();
                childs.put("Sub Item", d);
                secList.add(childs);
            }
            result.add(secList);
        } else {
            return result;
        }

    }

    return result;

}

@Override
public boolean onChildClick(ExpandableListView parent, View v,
        int groupPosition, int childPosition, long id) {

    // GET TITLE
    int idTitle = getResources().getIdentifier(c + alphabet[groupPosition],
            "array", "dk.android.houseenabler");

    String[] Rchilds = getResources().getStringArray(idTitle);

    // GET Desctiption

    int idDesc = getResources().getIdentifier(
            c + alphabet[groupPosition] + "_desc", "array",
            "dk.android.houseenabler");

    String[] RDesc = getResources().getStringArray(idDesc);

    Intent intent2 = new Intent().setClass(this, Description.class);
    intent2.putExtra("title", Rchilds[childPosition]);
    intent2.putExtra("description", RDesc[childPosition]);
    startActivity(intent2);

    return true;
}

/* This function is called on expansion of the group */
public void onGroupExpand(int groupPosition, View v, ViewGroup vg) {

}
}

Here is an image of the running application.
http://www.thomasbolander.dk/app.jpg

  • 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-31T21:56:42+00:00Added an answer on May 31, 2026 at 9:56 pm

    I found the solution!

        SimpleExpandableListAdapter expListAdapter = new SimpleExpandableListAdapter(
                this, createGroupList(), // Creating group List.
                R.layout.group_row, // Group item layout XML.
                new String[] { "Group Item" }, // the key of group item.
                new int[] { R.id.row_name }, // ID of each group item.-Data
                                                // under the key goes into
                                                // this TextView.
                createChildList(), // childData describes second-level
                                    // entries.
                R.layout.child_row, // Layout for sub-level entries(second
                                    // level).
                new String[] { "Sub Item" }, // Keys in childData maps to
                                                // display.
                new int[] { R.id.grp_child } // Data under the keys above go
                                                // into these TextViews.
        ) {
            @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 Checkbox in tab: "+ c + ", on Group: " + groupPosition
                            + ", on Child: " + childPosition;
                    CheckBox cb = (CheckBox) v.findViewById(R.id.check);
                    cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {
                        public void onCheckedChanged(CompoundButton arg0,
                                boolean arg1) {
                            Toast toast = Toast.makeText(ExpandableActivity.this, value, 2000);
                            toast.show();
                        }
                    });
                }
    
                return v;
            }
        };
        setListAdapter(expListAdapter); // setting the adapter in the list.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to set a OnCheckedChangeListener to a CheckBox but my application exits
Set rs = conn.Execute(Statement) //rs has 6 fields I want to add the current
I have a problem with listview which list item contain a checkbox. When i
I want to put a Listener over a CheckBox . I looked for info
I'm coding a really basic check list app. The user can add tasks and
I have an application with three textviews and one checkbox in each row of
I have this code for an event handler: rbM.setOnCheckedChangeListener(new OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton
Set<Type> union = new HashSet<Type>(s1); union.addAll(s2); AND Set <Type> union = new HashSet<Type>(); union.addAll(s1);
Set content of table ... ViewState[Table1] = Table1; // When remove this line, table
set dateformat dmy select isdate('31/1/2012') I thought by going into Change the format of

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.