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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:07:43+00:00 2026-06-11T14:07:43+00:00

I need to use Android ExpandableListView with custom layout for each group(groups have one

  • 0

I need to use Android ExpandableListView with custom layout for each group(groups have one child). To accomplish this, I’ve created a class which extends BaseExpandableListAdapter. On the getChildView method, I’ve created the view of each child. It works. When I click a group, its child comes with true layout. However, during the debuging, I see that it triggers getchildview method many times, so it is too slow to display child. Because there are a lot of operations on each child (db operations, dynamic sub layouts…).

There are a small project, which similar to my project(Logic and code structure are same, only layout code and code of creating each child view are different).

public class MainActivity extends Activity {

private ArrayList<String> groups;
private ArrayList<ArrayList<ArrayList<String>>> childs;

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

    setContentView(R.layout.activity_main);

    ExpandableListView l = (ExpandableListView)findViewById(R.id.expandableListView1);

    loadData();


    final myExpandableAdapter adapter = new myExpandableAdapter(this, groups, childs);
    l.setAdapter(adapter);


}

public class myExpandableAdapter extends BaseExpandableListAdapter {

    private ArrayList<String> groups;

    private ArrayList<ArrayList<ArrayList<String>>> children;

    private Context context;

    public myExpandableAdapter(Context context, ArrayList<String> groups, ArrayList<ArrayList<ArrayList<String>>> children) {
        this.context = context;
        this.groups = groups;
        this.children = childs;
    }


    @Override
    public boolean areAllItemsEnabled()
    {
        return true;
    }


    public ArrayList<String> getChild(int groupPosition, int childPosition) {
        return children.get(groupPosition).get(childPosition);
    }

    public long getChildId(int groupPosition, int childPosition) {
        return childPosition;
    }


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

        String child=(String)getChild(groupPosition, childPosition).get(0);
         switch (groupPosition){

        case 0:
            LayoutInflater inflater =  (LayoutInflater)getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.child_row, null);
            TextView tvPlayerName = (TextView) convertView.findViewById(R.id.tvPlayerName);
            tvPlayerName.setText(child);

            break;

        case 1:
            LayoutInflater inflater1 =  (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater1.inflate(R.layout.child_row1, null);
            TextView tvPlayerName1 = (TextView) convertView.findViewById(R.id.tvPlayerName);
            tvPlayerName1.setText(child);
            Button btn=(Button)convertView.findViewById(R.id.button1);
            btn.setOnClickListener(new OnClickListener() {

                public void onClick(View v) {
                    TextView tv=(TextView)findViewById(R.id.tv);
                    tv.setText("Clicked");
                }
            });

            break; 
        case 2:
            LayoutInflater inflater2 =  (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater2.inflate(R.layout.child_row1, null);
            TextView tvPlayerName12 = (TextView) convertView.findViewById(R.id.tvPlayerName);
            tvPlayerName12.setText(child);
            Button btn2=(Button)convertView.findViewById(R.id.button1);
            btn2.setOnClickListener(new OnClickListener() {

                public void onClick(View v) {
                    TextView tv=(TextView)findViewById(R.id.tv);
                    tv.setText("Clicked");
                }
            });

            break; 
     }
        return convertView;

    }

    public int getChildrenCount(int groupPosition) {
        return children.get(groupPosition).size();
    }

    public String getGroup(int groupPosition) {
        return groups.get(groupPosition);
    }

    public int getGroupCount() {
        return groups.size();
    }

    public long getGroupId(int groupPosition) {
        return groupPosition;
    }

    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {

        String group = (String) getGroup(groupPosition);

        if (convertView == null) {
            LayoutInflater infalInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = infalInflater.inflate(R.layout.expandablelistview_group, null);
        }

        TextView grouptxt = (TextView) convertView.findViewById(R.id.TextViewGroup);

        grouptxt.setText(group);

        return convertView;
    }

    public boolean hasStableIds() {
        return true;
    }

    public boolean isChildSelectable(int arg0, int arg1) {
        return true;
    }

}

private void loadData(){
    groups= new ArrayList<String>();
    childs= new ArrayList<ArrayList<ArrayList<String>>>();

    groups.add("Group 1");
    groups.add("Group 2");
    groups.add("Group 3");

    childs.add(new ArrayList<ArrayList<String>>());
    childs.get(0).add(new ArrayList<String>());
    childs.get(0).get(0).add("Child 1 group 1");


    childs.add(new ArrayList<ArrayList<String>>());
    childs.get(1).add(new ArrayList<String>());
    childs.get(1).get(0).add("Child 1 group 2");


    childs.add(new ArrayList<ArrayList<String>>());
    childs.get(2).add(new ArrayList<String>());
    childs.get(2).get(0).add("Child 1 group 3");

}}

During debugging, If I click any group, it comes to String child=(String)getChild(groupPosition, childPosition).get(0); line. After break; }return convertView;, it comes to there again and again, and then it displays layout.

activity_main.xml

<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_alignParentLeft="true"
    android:layout_centerVertical="true"
    android:layout_marginLeft="34dp" >
</ExpandableListView>

expandablelistview_group.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"> 
<TextView
    android:id="@+id/TextViewGroup" 
    android:layout_width="wrap_content"
    android:layout_height="50px"
    android:layout_marginLeft="50px"
    android:gravity="center_vertical"
>
</TextView>

child_row.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<TextView
    android:id="@+id/tvPlayerName"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="TextView" />

<CheckBox
    android:id="@+id/checkBox1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="CheckBox" />

childrow1.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >

    <TextView
    android:id="@+id/tv"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Row1" />

<TextView
    android:id="@+id/tvPlayerName"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="TextView" />

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button" />

Is there any suggestion to solve this.

Thanks

  • 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-11T14:07:44+00:00Added an answer on June 11, 2026 at 2:07 pm

    instead of inflating the view from getChildView use Holder read here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing an android application. Now i have created one function which create
I need to use 3D animation in my android application . I have tried
I have an Android 2.2 project that I need to use the facebook api
I need to use ExpandableList in my app. I found this example: http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/ExpandableList1.html which
I need to use maps on running in a physical Android device, how do
I need to use a plist from an existing iOS app in my android
Possible Duplicate: JSON Parsing in Android As I find out I need to use
I am developping an Android app, and I need to use java Signature class
i need some help in addition to android-layouts. For eyample: Actually I use a
I need use this method with three distinct classes: Orders, Customers, Suppliers public void

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.