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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:12:34+00:00 2026-06-04T00:12:34+00:00

I am trying to implement a ExpandableListView in Android by implementing a custom adapter

  • 0

I am trying to implement a ExpandableListView in Android by implementing a custom adapter but I am not getting any output on the screen.

The main xml layout is:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="This is an expandable listview"
    />
<ExpandableListView
    android:id="@android:id/list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    />


</LinearLayout>

The group layout file is:

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

<TextView
    android:id="@+id/tvPlayerName"
    android:textSize="14px"
    android:textStyle="normal"
    android:layout_width="150px"
    android:layout_height="wrap_content"
    />

The child layout file is:

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

<TextView
    android:id="@+id/tvPlayerName"
    android:textSize="14px"
    android:textStyle="normal"
    android:layout_width="150px"
    android:layout_height="wrap_content"
    />

</LinearLayout>

AND lastly, the activity class file is:

public class ExpandableListViewTest extends ExpandableListActivity {
 String groupElements[] = {"India","Austrailia","England","South Africa"};
 String childElements[][] = {
    {"Sachin Tendulkar","Raina","Dhoni","Yuvraj"},
    {"Ponting","Adam Gilchrist","Michael Clarke"},
    {"Andrew Strauss","Kevin Peterson","Nasir Hussain"},
    {"Grame Smith","AB de Villiers","Jacques Kallis"}
};

int width;
ExpandableListView expList;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    //Setup our adapter
    MyExpandableAdapter mAdapter = new MyExpandableAdapter(this);
    setListAdapter(mAdapter);
}
public class MyExpandableAdapter extends BaseExpandableListAdapter
{
   private Context myContext;

   public MyExpandableAdapter(Context context)
   {
       this.myContext= context;
   }

@Override
public Object getChild(int groupPosition, int childPosition) {
    // TODO Auto-generated method stub
    return childElements[groupPosition][childPosition];
}

@Override
public long getChildId(int groupPosition, int childPosition) {
    // TODO Auto-generated method stub
    return childPosition;
}

@Override
public View getChildView(int groupPosition, int childPosition,
        boolean isLastChild, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    if(convertView == null)
    {
        LayoutInflater inflater = getLayoutInflater();
        convertView = inflater.inflate(R.layout.child, parent,false);
    }
    TextView tvPlayerName = 
       (TextView)convertView.findViewById(R.id.tvPlayerName);
    tvPlayerName.setText(childElements[groupPosition][childPosition]);

    return convertView;

}

@Override
public int getChildrenCount(int groupPosition) {
    // TODO Auto-generated method stub
    return childElements[groupPosition].length;
}

@Override
public Object getGroup(int groupPosition) {
    // TODO Auto-generated method stub
    return null;
}

@Override
public int getGroupCount() {
    // TODO Auto-generated method stub
    return 0;
}

@Override
public long getGroupId(int groupPosition) {
    // TODO Auto-generated method stub
    return 0;
}

@Override
public View getGroupView(int groupPosition, boolean isExpanded,
        View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    if(convertView == null)
    {
        LayoutInflater inflater = getLayoutInflater();
        convertView = inflater.inflate(R.layout.group,parent,false);
    }
    TextView tvGroupName = (TextView)convertView.findViewById(R.id.groupName);
    //tvGroupName.setText(groupElements[groupPosition]);
    tvGroupName.setText("Group Row");

    return convertView;

}

@Override
public boolean hasStableIds() {
    // TODO Auto-generated method stub
    return false;
}

@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
    // TODO Auto-generated method stub
    return false;
}


}

}

All seems straighhtforward enough but after running the app, the screen stays blank.Any help/ideal is appreciated.

  • 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-04T00:12:35+00:00Added an answer on June 4, 2026 at 12:12 am

    Your code looks incomplete. You’ve just got placeholders in the methods getGroup, getGroupId and getGroupCount. They should reference your groupElements array.

    The fact that getGroupCount currently returns zero would be enough for the ExpandableListView to not display anything.

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

Sidebar

Related Questions

I am trying to implement ExpandableListView in android. But I did not find any
I'm currently trying to implement an ExtendedListView that uses an Adapter. I'm implementing the
I'm trying implement my project in Apache Struts 2 but I'm not very familiar
Trying to implement sticky footer but its not working as planned. It throws it
im trying to implement a custom error page, what i want to be able
Iam trying to implement a simple JMS(traditional not using springs) code in eclipse using
Im trying to implement an activity that uses ExpandableListView and I have gotten so
I am trying implement a photo gallery similar to facebook in Android. I was
Trying to implement AVAudioplayer and get some metering data of the played music, but
Trying to implement the new FP 10.1 Global error handler into my projects but

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.