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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:14:56+00:00 2026-06-02T05:14:56+00:00

I am trying to create an expandable list view like the one described here

  • 0

I am trying to create an expandable list view like the one described here. I am using the following adapter for the list:

mAdapter = new SimpleExpandableListAdapter(
                this, groupData,
                android.R.layout.simple_expandable_list_item_1,
                new String[] { NAME, IS_EVEN },
                new int[] { android.R.id.text1, android.R.id.text2 },
                childData,
                android.R.layout.simple_list_item_single_choice,
                new String[] { NAME, IS_EVEN },
                new int[] { android.R.id.text1, android.R.id.text2 }
                );

My parent and children have the same children, but I need to be able to select a child from a parent and a different child from another parent.
The radio buttons appear but are grouped across the parent list items. That is, you cannot select a child from on parent and a different child from another parent. How can I edit this code to allow that?

I got this code from here:

public class myClass extends ExpandableListActivity {

final Context mContext = this;

public static final String GROUP_ID = "Group";
public static final String CHILD_ID = "Child";
public static final int GROUPS = 2;
public static final int CHILDREN = 2;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    /* Set up the adapter for the expandable list */
    setListAdapter(new SimpleExpandableListAdapter(
            mContext,
            getGroups(),
            android.R.layout.simple_expandable_list_item_1,
            new String[] {GROUP_ID}, new int[] {android.R.id.text1},
            getChildren(),
            android.R.layout.simple_list_item_single_choice,
            new String[] {CHILD_ID}, new int[] {android.R.id.text1}));

    /* Get the list, and set the choice mode to multiple - why no WORKY? */
    final ExpandableListView listView = getExpandableListView();
    listView.setItemsCanFocus(false);
    listView.setChoiceMode(ExpandableListView.CHOICE_MODE_SINGLE);
    listView.setOnChildClickListener(cl);
}

private OnChildClickListener cl = new OnChildClickListener(){

    @Override
    public boolean onChildClick(ExpandableListView parent, View v,
            int groupPosition, int childPosition, long id) {
        int position = groupPosition * (CHILDREN + 1) + childPosition + 1;
        if (getExpandableListView().isItemChecked(position)) {
            getExpandableListView().setItemChecked(position, false);
        } else {
            getExpandableListView().setItemChecked(position, true);
        }
        return false;
    }
};

/* Generate the names of the groups - not the problem, works fine. */
public List<Map<String, String>> getGroups() {
    List<Map<String, String>> list = new ArrayList<Map<String, String>>();
    Map<String, String> map;
    for (int i = 0; i < GROUPS; ++i) {
        map = new HashMap<String, String>();
        map.put(GROUP_ID, "Group " + i);
        list.add(map);  
    }
    return list;
}

/* Generates the names of the children - not the problem, works fine. */
public List<List<Map<String, String>>> getChildren() {
    List<List<Map<String, String>>> list = new ArrayList<List<Map<String, String>>>();
    List<Map<String, String>> subList = new ArrayList<Map<String, String>>();
    Map<String, String> map;
    for (int j = 0; j < CHILDREN; ++j) {
        map = new HashMap<String, String>();
        map.put(CHILD_ID, "Child " + j);
        subList.add(map);
    }
    for (int i = 0; i < GROUPS; ++i) {
        list.add(subList);
    }
    return list;
}

}

  • 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-02T05:14:57+00:00Added an answer on June 2, 2026 at 5:14 am
    private OnChildClickListener cl = new OnChildClickListener(){
    
            public boolean onChildClick(ExpandableListView parent, View v,
                    int groupPosition, int childPosition, long id) {
    
                int position;
                int setposition =childPosition+1;
    
                if(groupPosition ==0)
                {
    
                     position = groupPosition * (CHILDREN + 1) + childPosition + 1;
                     if (getExpandableListView().isItemChecked( setposition)) {
                        getExpandableListView().setItemChecked(setposition, false);
                    } else {
                        getExpandableListView().setItemChecked( setposition, true);
                    }
                }
    
                else
                    {
    
                     position = count+childPosition + 1;
                     setposition =childPosition+2;
    
                     if (getExpandableListView().isItemChecked( setposition)) {
                        getExpandableListView().setItemChecked(setposition, false);
                    } else {
                        getExpandableListView().setItemChecked( setposition, true);
                    }
                    }
    
                System.out.println("is checked? at position:"+ getExpandableListView().isItemChecked(setposition)+position);
    
    
                return false;
            }
        };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok so I am trying create a login script, here I am using PHP5
I'm trying to create an expandable menu item in android, which will look like
I am trying to create an expandable listview similar to the expandable list shown
Trying to create collapsible / expandable divs using jQuery, but it's not working for
I'm trying to create a form that has an expandable widget. The problem is
I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can
Trying to create a QtRuby application, I get the following error: /usr/lib64/ruby/site_ruby/1.8/Qt/qtruby4.rb:2144: [BUG] Segmentation
Trying to create several layers of folders at once C:\pie\applepie\recipies\ without using several different
So, I'm trying to create a random vector (think geometry, not an expandable array),
hi I'm trying create chat using node.js I see example in http://chat.nodejs.org/ I have

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.