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

  • Home
  • SEARCH
  • 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 8646241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:45:22+00:00 2026-06-12T12:45:22+00:00

Can we have 3 different ExpandableLists in same layout i.e., in main.xml? If so

  • 0

Can we have 3 different ExpandableLists in same layout i.e., in main.xml? If so can we use them differently in terms of android:list?

I have a requirement that I need to implement 3 individual expandableLists in the same layout. Can it be done?

  • 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-12T12:45:24+00:00Added an answer on June 12, 2026 at 12:45 pm

    Yes you can. I imagine simply using different ids would be more straight forward than android:list. But I wonder, are you trying to achieve an expandable list with 3 group rows and 1 group of child rows under each? Such that these are connected and look seamless? If so you can do it with one expandable list. Just an fyi. If that was your intention, I’ll get you a sample code to show you how it’s done. It’s very easy.

    EDIT: The reason you are getting that error is because you’re most probably trying to use an expandablelistactivity class, which assumes (practically) that there will only be one expandable list in the activity. You should use a regular activity class. Here is what i’ve just tested and works.

    package com.mango.stackoverflow;
    
    import android.os.Bundle;
    import android.app.Activity;
    import android.view.Gravity;
    import android.view.Menu;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.AbsListView;
    import android.widget.BaseExpandableListAdapter;
    import android.widget.ExpandableListView;
    import android.widget.TextView;
    
    public class MainActivity extends Activity {
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            ExpandableListView TestExpandListView1 = (ExpandableListView) findViewById(R.id.expandableListView1);
            ExpandableListView TestExpandListView2 = (ExpandableListView) findViewById(R.id.expandableListView2);
            ExpandableListView TestExpandListView3 = (ExpandableListView) findViewById(R.id.expandableListView3);
            TestExpandableListAdapter TestExpandAdapter = new TestExpandableListAdapter();
            TestExpandListView1.setAdapter(TestExpandAdapter);
            TestExpandListView2.setAdapter(TestExpandAdapter);
            TestExpandListView3.setAdapter(TestExpandAdapter);
        }
    
    
        public class TestExpandableListAdapter extends BaseExpandableListAdapter {
    
            private String[] groups = { "People Names -- 1st GROUP", "Dog Names", "Cat Names", "Fish Names" };
            private String[][] children = {
                    { "Arnold", "Barry", "Chuck", "David" },
                    { "Ace", "Bandit", "Cha-Cha", "Deuce" },
                    { "Fluffy", "Snuggles" },
                    { "Goldy", "Bubbles" }
            };
    
            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(MainActivity.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) {
                TextView textView = getGenericView();
                textView.setText(getChild(groupPosition, childPosition).toString());
                return textView;
            }
    
            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;
            }
    
        }
    
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            getMenuInflater().inflate(R.menu.activity_main, menu);
            return true;
        }
    }
    

    I’m posting the xml as well, in case I wasn’t being clear about the id instantiation (PLEASE take note — Although i used “wrap_content” for the layout_height in the xml for the sake of speed, it is DEFINITELY not best practices to do so for expandablelistviews or any listview, it uses much more resources than the other alternatives would):

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    
        <ExpandableListView
            android:id="@+id/expandableListView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true" >
        </ExpandableListView>
    
            <ExpandableListView
            android:id="@+id/expandableListView2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/expandableListView1" >
        </ExpandableListView>
    
                    <ExpandableListView
            android:id="@+id/expandableListView3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/expandableListView2" >
        </ExpandableListView>
    
    
    </RelativeLayout>
    

    And here is a picture

    emulator results

    • That being posted, I don’t want to instruct you how to do your code, but just to level with you. having this many expandable listviews in one activity, especially if you’re inflating views is not going to be the most… elegant implemention. I don’t know what you’re trying to do, but if they are to be connected like mine were or even just in a vertical panel, then it can be done with just one and be much more efficient.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have page where I use model which can have different types (depending by
I have jaxb objects against an XML schema. That xml schema can have different
Create a function that can have different argument list. something like this void s(int
I want to create a website with various users. The users can have different
How can I have different colors for different tabs in SuperTabNavigator. Below is the
I've got a table recording views of programs. Each program can have two different
Shaders can have lots of different uniform names + attributes. How can I make
I have a phone number field that can have lots of different characters such
I have to pass back information from a different source and can have a
With the XmlSerializer I can have my members in different namespaces to the parent

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.