{"id":1358,"date":"2016-04-11T05:41:16","date_gmt":"2016-04-11T05:41:16","guid":{"rendered":"http:\/\/abhiandroid.com\/ui\/?p=1358"},"modified":"2019-06-12T12:58:20","modified_gmt":"2019-06-12T12:58:20","slug":"baseexpandablelistadapter-example-android-studio","status":"publish","type":"post","link":"https:\/\/abhiandroid.com\/ui\/baseexpandablelistadapter-example-android-studio.html","title":{"rendered":"BaseExpandableListAdapter With Example In Android Studio"},"content":{"rendered":"<p>BaseExpandableListAdapter is a base class for the ExpandableListAdapter which is used to fill\u00a0the data and Views from some data (i.e. Arraylist, HashMap etc) to an ExpandableListView. For Creating a custom ExpandableListView we need to create a custom class and then extends\u00a0BaseExpandableListAdapter class in that class.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1473\" src=\"\/ui\/wp-content\/uploads\/2016\/04\/BaseExpandableListAdapter-in-Android.jpg\" alt=\"BaseExpandableListAdapter in Android\" width=\"485\" height=\"253\" srcset=\"https:\/\/abhiandroid.com\/ui\/wp-content\/uploads\/2016\/04\/BaseExpandableListAdapter-in-Android.jpg 485w, https:\/\/abhiandroid.com\/ui\/wp-content\/uploads\/2016\/04\/BaseExpandableListAdapter-in-Android-300x156.jpg 300w\" sizes=\"auto, (max-width: 485px) 100vw, 485px\" \/><\/p>\n<p>An adapter is a bridge between UI component and data source which\u00a0fill data in UI component. It holds the data and then send the data to Adapter view then view can takes the data from the Adapter view and shows the data on different views like as ExpandableListView or you can say An adapter is that links an ExpandableListView with the underlying data. The implementation of this interface will provide access to the data of the children (categorized by groups), and also instantiate views for the children and groups.<\/p>\n<p>Below is an example code of BaseExpandableListAdapter \u00a0in which we create a\u00a0custom adapter class named \u201cMyAdapter\u201d and then extends BaseExpandableListAdapter in that class.<\/p>\n<pre>public class MyAdapter extends BaseExpandableListAdapter {\r\n\r\n@Override\r\npublic int getGroupCount() {\r\nreturn 0;\r\n}\r\n\r\n@Override\r\npublic int getChildrenCount(int groupPosition) {\r\nreturn 0;\r\n}\r\n\r\n@Override\r\npublic Object getGroup(int groupPosition) {\r\nreturn null;\r\n}\r\n\r\n@Override\r\npublic Object getChild(int groupPosition, int childPosition) {\r\nreturn null;\r\n}\r\n\r\n@Override\r\npublic long getGroupId(int groupPosition) {\r\nreturn 0;\r\n}\r\n\r\n@Override\r\npublic long getChildId(int groupPosition, int childPosition) {\r\nreturn 0;\r\n}\r\n\r\n@Override\r\npublic boolean hasStableIds() {\r\nreturn false;\r\n}\r\n\r\n@Override\r\npublic View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {\r\nreturn null;\r\n}\r\n\r\n@Override\r\npublic View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {\r\nreturn null;\r\n}\r\n\r\n@Override\r\npublic boolean isChildSelectable(int groupPosition, int childPosition) {\r\nreturn false;\r\n}\r\n}\r\n<\/pre>\n<p>In above code snippet we see the overrided functions of BaseExpandableListAdapter which are used to set the data in the ExpandabelListView. There are mainly two methods named getChildView() and getGroupView() that are used to create the View corresponding to our layout (i.e. one is for the items (child items) and one for the groups (parent)).<\/p>\n<p><span style=\"color: #008000;\"><strong>1. getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent):<\/strong><\/span>\u00a0This method is used when we need to create a child View means a child item for a parent or group.<\/p>\n<p><strong>Paramters:<\/strong><\/p>\n<ul>\n<li><strong>groupPosition:<\/strong>\u00a0This is the first parameter that tells the position for the parent(group) of the current child. The function returns an integer type value.<\/li>\n<li><strong>childPosition:<\/strong>\u00a0This is the second parameter that tells the position for current child item of the parent.<\/li>\n<li><strong>isLastChild:<\/strong>\u00a0This is the third parameter that returns Boolean value. It returns true if the current child item is the last child within its group and false if it\u2019s not.<\/li>\n<li><strong>convertView<\/strong>: This\u00a0is the fourth parameter that returns View which is used to set the layout for child items.<\/li>\n<li><strong>Parent:<\/strong> parent is the fifth or last parameter that is used to set the view for the parent or group item. \u00a0The eventual parent of this new View.<\/li>\n<\/ul>\n<p><span style=\"color: #008000;\"><strong>2. View\u00a0 getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent):<\/strong><\/span> This method is used when we need to create our group or parent View .<\/p>\n<p><strong>Paramters:<\/strong><\/p>\n<ul>\n<li><strong>groupPosition:<\/strong>\u00a0This is the first parameter that tells the position for the parent or group of the child. The function returns an integer type value.<\/li>\n<li><strong>isExpanded:<\/strong>\u00a0This\u00a0is the second parameter that returns Boolean value. It returns true if the current group is expanded and false if it\u2019s not.<\/li>\n<li><strong>convertView:<\/strong>\u00a0This is the fourth parameter that returns View which is used to set the layout for group items.<\/li>\n<li><strong>Parent:<\/strong>\u00a0This\u00a0is the fifth or last parameter that is used to set the view for the parent or group item. \u00a0The eventual parent of this new View.<\/li>\n<\/ul>\n<p><span style=\"color: #008000;\"><strong>3. getChild(int groupPosition, int childPosition):<\/strong><\/span> This method gets the data associated with the given child within the given group.<\/p>\n<p><strong>Parameters:<\/strong><\/p>\n<ul>\n<li><strong>groupPosition:<\/strong>\u00a0This is the first parameter that tells the position for the parent or group of the child. This function returns an integer type value<\/li>\n<\/ul>\n<ul>\n<li><strong>childPosition:<\/strong>\u00a0This is the second parameter that tells the position for the child of the given group. This function returns an integer type value.<\/li>\n<\/ul>\n<p><span style=\"color: #008000;\"><strong>4. getGroup(int groupPosition):<\/strong><\/span> This method gets the data associated with the given group.<\/p>\n<p><strong>Parameters:<\/strong><\/p>\n<ul>\n<li><strong>groupPosition:<\/strong>\u00a0This is the parameter that tells the position for the parent or group of the child. This function returns an integer type value<\/li>\n<\/ul>\n<p><span style=\"color: #008000;\"><strong>5. getChildrenCount(int groupPosition):<\/strong><\/span> This function gets the number of children in a specified group.<\/p>\n<p><strong>Parameters:<\/strong><\/p>\n<ul>\n<li><strong>groupPosition:<\/strong>\u00a0This\u00a0parameter tells the position for the parent or group of the child and by using that position we calculate the number of children in that group.<\/li>\n<\/ul>\n<p><span style=\"color: #008000;\"><strong>6. getGroupCount():<\/strong><\/span> This function is used to get the total number of groups.<\/p>\n<p><span style=\"color: #008000;\"><strong>7. getGroupId(int groupPosition):<\/strong><\/span> This function is used to get the ID for the group at the given position.<\/p>\n<p><strong>Parameters:<\/strong><\/p>\n<ul>\n<li><strong>groupPosition:<\/strong>\u00a0This parameter tells the position for the parent or group of the child and by using that position we get the ID for the group.<\/li>\n<\/ul>\n<p><span style=\"color: #008000;\"><strong>8. getChildId(int groupPosition, int childPosition):<\/strong><\/span> This function is used to gets the ID for the given child within the given group.<\/p>\n<p><strong>Parameters:<\/strong><\/p>\n<ul>\n<li><strong>groupPosition:<\/strong>\u00a0This is the first parameter that tells the position for the parent or group of the child. This function returns an integer type value<\/li>\n<\/ul>\n<ul>\n<li><strong>childPosition:<\/strong>\u00a0This is the second parameter that tells the position for the child of the given group. This function returns an integer type value and by using\u00a0 that value\u00a0we gets the ID for that.<\/li>\n<\/ul>\n<p><span style=\"color: #008000;\"><strong>9. hasStableIds:<\/strong><\/span> This method Indicates that whether the child and group ID\u2019s are stable across changes to the underlying data.<\/p>\n<p><span style=\"color: #008000;\"><strong>10. isChildSelectable(int groupPosition, int childPosition):<\/strong><\/span> This mehod checks whether the child at the specified position is selectable or not. This method returns an Boolean value means true or false. It returns true if the child is selectable and false if it\u2019s not.<\/p>\n<p><strong>Parameters:<\/strong><\/p>\n<ul>\n<li><strong>groupPosition:<\/strong>\u00a0This\u00a0is the first parameter that tells the position for the parent or group of the child. This function returns an integer type value.<\/li>\n<li><strong>childPosition:<\/strong>\u00a0This\u00a0is the second parameter that tells the position for the child of the given group. This function returns an integer type value and by using that value we checks whether the child is selectable or not.<\/li>\n<\/ul>\n<hr \/>\n<h4><strong>BaseExpandableListAdapter\u00a0<\/strong><strong>Example In Android Studio<\/strong><\/h4>\n<p>Below is the example of BaseExpandableListAdapter in Android\u00a0where\u00a0we display an ExpandableListView with team name and their players. In this example we display Team names as an group items and their Player names as an child items for a particular group. In this we implement setOnChildClickListener() and setOnGroupClickListener() events and whenever a user clicks on a child or a group item the name of the item (player or team) is displayed by using a Toast.<\/p>\n<p style=\"text-align: center;\"><a class=\"download\" href=\"https:\/\/github.com\/abhisheksaini4\/BaseExpandableListAdapter\" target=\"_blank\" rel=\"nofollow\">Download Code<\/a><a class=\"help\" title=\"Learn How To Download Code And Import In Android Studio\" href=\"\/androidstudio\/download-code-abhiandroid\" target=\"_blank\" rel=\"nofollow\"> ? <\/a><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1472\" src=\"\/ui\/wp-content\/uploads\/2016\/04\/BaseExpandableListAdapter-Example-In-Android-Studio.jpg\" alt=\"BaseExpandableListAdapter Example In Android Studio\" width=\"251\" height=\"357\" srcset=\"https:\/\/abhiandroid.com\/ui\/wp-content\/uploads\/2016\/04\/BaseExpandableListAdapter-Example-In-Android-Studio.jpg 251w, https:\/\/abhiandroid.com\/ui\/wp-content\/uploads\/2016\/04\/BaseExpandableListAdapter-Example-In-Android-Studio-211x300.jpg 211w\" sizes=\"auto, (max-width: 251px) 100vw, 251px\" \/><\/p>\n<p><strong><span style=\"color: #008000;\">Step 1<\/span>:\u00a0<\/strong>Create a new project and name it BaseExpandableListAdapter<\/p>\n<p><strong><span style=\"color: #008000;\">Step 2:<\/span>\u00a0<\/strong>Open res -&gt; layout -&gt;activity_main.xml (or) main.xml and add following code:<\/p>\n<p>In this step we open an xml file and add the code for displaying an ExpandableListView by using its different attributes.<\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\r\n&lt;RelativeLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    android:layout_width=\"match_parent\"\r\n    android:layout_height=\"match_parent\"\r\n    android:orientation=\"vertical\"&gt;\r\n\r\n    &lt;ExpandableListView\r\n        android:id=\"@+id\/simpleExpandableListView\"\r\n        android:layout_width=\"match_parent\"\r\n        android:layout_height=\"fill_parent\"\r\n        android:divider=\"#0f0\"\r\n        android:dividerHeight=\"1dp\" \/&gt;\r\n\r\n&lt;\/RelativeLayout&gt;<\/pre>\n<p><strong><span style=\"color: #008000;\">Step 3:<\/span>\u00a0<\/strong>Create a new xml file for group items Open res -&gt; layout-&gt; group_items.xml and add following code:<\/p>\n<p>In this step we add the code for displaying a TextView for team names.<\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;LinearLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    android:layout_width=\"fill_parent\"\r\n    android:layout_height=\"55dip\"\r\n    android:orientation=\"vertical\" &gt;\r\n\r\n    &lt;TextView\r\n        android:id=\"@+id\/heading\"\r\n        android:layout_width=\"wrap_content\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:paddingLeft=\"35sp\"\r\n        android:textAppearance=\"?android:attr\/textAppearanceLarge\"\r\n        android:textStyle=\"bold\" \/&gt;\r\n\r\n&lt;\/LinearLayout&gt;<\/pre>\n<p><strong><span style=\"color: #008000;\">Step 4:<\/span>\u00a0<\/strong>Create a new xml file for group items Open res -&gt; layout -&gt;child_items.xml and add following code :<\/p>\n<p>In this step we add the code for displaying text view for player name.<\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;RelativeLayout\r\n    xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    android:layout_width=\"match_parent\"\r\n    android:layout_height=\"match_parent\"\r\n    android:orientation=\"vertical\"&gt;\r\n\r\n    &lt;TextView\r\n        android:id=\"@+id\/childItem\"\r\n        android:layout_width=\"wrap_content\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:layout_alignParentTop=\"true\"\r\n        android:layout_marginLeft=\"10dp\"\r\n        android:textAppearance=\"?android:attr\/textAppearanceMedium\" \/&gt;\r\n\r\n&lt;\/RelativeLayout&gt;<\/pre>\n<p><strong><span style=\"color: #008000;\">Step 5:<\/span>\u00a0<\/strong>Open\u00a0 \u00a0src -&gt; package -&gt; MainActivity.java<\/p>\n<p>In this step we open\u00a0MainActivity\u00a0and\u00a0add the code to\u00a0\u00a0initiate the ExpandableListView and then add the data to lists for displaying in a ExpandableListView using model classes. Finally set the Adapter that fills the data in the ExpandableListView. In this we implement setOnChildClickListener() and setOnGroupClickListener() events and whenever a user clicks on a child or a group item the name of the item is display by using a Toast.<\/p>\n<pre>package example.abhiandroid.BaseExpandableListAdapterExample;\r\n\r\nimport android.os.Bundle;\r\nimport android.support.v7.app.AppCompatActivity;\r\nimport android.view.View;\r\nimport android.widget.ExpandableListView;\r\nimport android.widget.Toast;\r\n\r\nimport java.util.ArrayList;\r\nimport java.util.LinkedHashMap;\r\n\r\npublic class MainActivity extends AppCompatActivity {\r\n\r\n    private LinkedHashMap&lt;String, GroupInfo&gt; team = new LinkedHashMap&lt;String, GroupInfo&gt;();\r\n    private ArrayList&lt;GroupInfo&gt; deptList = new ArrayList&lt;GroupInfo&gt;();\r\n\r\n    private CustomAdapter listAdapter;\r\n    private ExpandableListView simpleExpandableListView;\r\n\r\n    @Override\r\n    public void onCreate(Bundle savedInstanceState) {\r\n        super.onCreate(savedInstanceState);\r\n        setContentView(R.layout.activity_main);\r\n\r\n        \/\/ add data for displaying in expandable list view\r\n        loadData();\r\n\r\n        \/\/get reference of the ExpandableListView\r\n        simpleExpandableListView = (ExpandableListView) findViewById(R.id.simpleExpandableListView);\r\n        \/\/ create the adapter by passing your ArrayList data\r\n        listAdapter = new CustomAdapter(MainActivity.this, deptList);\r\n        \/\/ attach the adapter to the expandable list view\r\n        simpleExpandableListView.setAdapter(listAdapter);\r\n\r\n        \/\/ setOnChildClickListener listener for child row click\r\n        simpleExpandableListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {\r\n            @Override\r\n            public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {\r\n                \/\/get the group header\r\n                GroupInfo headerInfo = deptList.get(groupPosition);\r\n                \/\/get the child info\r\n                ChildInfo detailInfo = headerInfo.getPlayerName().get(childPosition);\r\n                \/\/display it or do something with it\r\n                Toast.makeText(getBaseContext(), \" Team And Player :: \" + headerInfo.getName()\r\n                        + \"\/\" + detailInfo.getName(), Toast.LENGTH_LONG).show();\r\n                return false;\r\n            }\r\n        });\r\n        \/\/ setOnGroupClickListener listener for group heading click\r\n        simpleExpandableListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {\r\n            @Override\r\n            public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {\r\n                \/\/get the group header\r\n                GroupInfo headerInfo = deptList.get(groupPosition);\r\n                \/\/display it or do something with it\r\n                Toast.makeText(getBaseContext(), \" Team Name :: \" + headerInfo.getName(),\r\n                        Toast.LENGTH_LONG).show();\r\n\r\n                return false;\r\n            }\r\n        });\r\n\r\n\r\n    }\r\n\r\n    \/\/ load some initial data into out list\r\n    private void loadData() {\r\n\r\n        addProduct(\"India\", \"Virat Kohli\");\r\n        addProduct(\"India\", \"Mahendar Dhoni\");\r\n        addProduct(\"India\", \"Yuvraj Singh\");\r\n\r\n        addProduct(\"Australia\", \"Brat Lee\");\r\n        addProduct(\"Australia\", \"Hayden\");\r\n\r\n    }\r\n\r\n\r\n    \/\/ here we maintain team and player names\r\n    private int addProduct(String teamName, String playerName) {\r\n\r\n        int groupPosition = 0;\r\n\r\n        \/\/check the hash map if the group already exists\r\n        GroupInfo headerInfo = team.get(teamName);\r\n        \/\/add the group if doesn't exists\r\n        if (headerInfo == null) {\r\n            headerInfo = new GroupInfo();\r\n            headerInfo.setName(teamName);\r\n            team.put(teamName, headerInfo);\r\n            deptList.add(headerInfo);\r\n        }\r\n\r\n        \/\/ get the children for the group\r\n        ArrayList&lt;ChildInfo&gt; productList = headerInfo.getPlayerName();\r\n        \/\/ size of the children list\r\n        int listSize = productList.size();\r\n        \/\/ add to the counter\r\n        listSize++;\r\n\r\n        \/\/ create a new child and add that to the group\r\n        ChildInfo detailInfo = new ChildInfo();\r\n        detailInfo.setName(playerName);\r\n        productList.add(detailInfo);\r\n        headerInfo.setPlayerName(productList);\r\n\r\n        \/\/ find the group position inside the list\r\n        groupPosition = deptList.indexOf(headerInfo);\r\n        return groupPosition;\r\n    }\r\n\r\n}<\/pre>\n<p><strong><span style=\"color: #008000;\">Step 6:\u00a0<\/span><\/strong>Create a New Class Open -&gt; package &#8211; &gt; GroupInfo.Java and add the following code.<\/p>\n<p>In this step we create an class for set and get the group item name and child items info according to a particular group. GroupInfo is an model class used to set the name of the group item and child items information from your MainActivity and then get the information within Adapter class. Finally set the value to ExpandableListView.<\/p>\n<pre>package example.abhiandroid.BaseExpandableListAdapterExample;\r\n\r\nimport java.util.ArrayList;\r\n\r\npublic class GroupInfo {\r\n\r\n    private String teamName;\r\n    private ArrayList&lt;ChildInfo&gt; list = new ArrayList&lt;ChildInfo&gt;();\r\n\r\n    public String getName() {\r\n        return teamName;\r\n    }\r\n\r\n    public void setName(String teamName) {\r\n        this.teamName = teamName;\r\n    }\r\n\r\n    public ArrayList&lt;ChildInfo&gt; getPlayerName() {\r\n        return list;\r\n    }\r\n\r\n    public void setPlayerName(ArrayList&lt;ChildInfo&gt; playerName) {\r\n        this.list = playerName;\r\n    }\r\n\r\n}<\/pre>\n<p><strong><span style=\"color: #008000;\">Step 7:\u00a0<\/span><\/strong>Create a New Class Open -&gt; package &#8211; &gt; ChildInfo.Java and add the following code.<\/p>\n<p>In this step we create an class for set and get the name for the child item. ChildInfo is an model class used to set the name of the child item from your Mainactivity and then get the name within adapter class. Finally set the value to ExpandableListView.<\/p>\n<pre>package example.abhiandroid.BaseExpandableListAdapterExample;\r\n\r\npublic class ChildInfo {\r\n\r\n    private String playerName = \"\";\r\n\r\n    public String getName() {\r\n        return playerName;\r\n    }\r\n\r\n    public void setName(String playerName) {\r\n        this.playerName = playerName;\r\n    }\r\n\r\n}<\/pre>\n<p><span style=\"color: #008000;\"><strong>Step 8:<\/strong><\/span> Create a New Class Open -&gt; package &#8211; &gt; CustomAdapter.Java and add the following code.<\/p>\n<p>In this step we create an custom adapter and then extends BaseExpandableListAdapter in that class. Finally set the data in the ExpandableListView from GroupInfo and ChildInfo model classes.<\/p>\n<pre>package example.abhiandroid.BaseExpandableListAdapterExample;\r\n\r\nimport android.content.Context;\r\nimport android.view.LayoutInflater;\r\nimport android.view.View;\r\nimport android.view.ViewGroup;\r\nimport android.widget.BaseExpandableListAdapter;\r\nimport android.widget.TextView;\r\n\r\nimport java.util.ArrayList;\r\n\r\n\r\n\/**\r\n * Created by Gourav on 08-03-2016.\r\n *\/\r\npublic class CustomAdapter extends BaseExpandableListAdapter {\r\n\r\n    private Context context;\r\n    private ArrayList&lt;GroupInfo&gt; teamName;\r\n\r\n    public CustomAdapter(Context context, ArrayList&lt;GroupInfo&gt; deptList) {\r\n        this.context = context;\r\n        this.teamName = deptList;\r\n    }\r\n\r\n    @Override\r\n    public Object getChild(int groupPosition, int childPosition) {\r\n        ArrayList&lt;ChildInfo&gt; productList = teamName.get(groupPosition).getPlayerName();\r\n        return productList.get(childPosition);\r\n    }\r\n\r\n    @Override\r\n    public long getChildId(int groupPosition, int childPosition) {\r\n        return childPosition;\r\n    }\r\n\r\n    @Override\r\n    public View getChildView(int groupPosition, int childPosition, boolean isLastChild,\r\n                             View view, ViewGroup parent) {\r\n\r\n        ChildInfo detailInfo = (ChildInfo) getChild(groupPosition, childPosition);\r\n        if (view == null) {\r\n            LayoutInflater infalInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);\r\n            view = infalInflater.inflate(R.layout.child_items, null);\r\n        }\r\n        TextView childItem = (TextView) view.findViewById(R.id.childItem);\r\n        childItem.setText(detailInfo.getName().trim());\r\n\r\n        return view;\r\n    }\r\n\r\n    @Override\r\n    public int getChildrenCount(int groupPosition) {\r\n\r\n        ArrayList&lt;ChildInfo&gt; productList = teamName.get(groupPosition).getPlayerName();\r\n        return productList.size();\r\n\r\n    }\r\n\r\n    @Override\r\n    public Object getGroup(int groupPosition) {\r\n        return teamName.get(groupPosition);\r\n    }\r\n\r\n    @Override\r\n    public int getGroupCount() {\r\n        return teamName.size();\r\n    }\r\n\r\n    @Override\r\n    public long getGroupId(int groupPosition) {\r\n        return groupPosition;\r\n    }\r\n\r\n    @Override\r\n    public View getGroupView(int groupPosition, boolean isLastChild, View view,\r\n                             ViewGroup parent) {\r\n\r\n        GroupInfo headerInfo = (GroupInfo) getGroup(groupPosition);\r\n        if (view == null) {\r\n            LayoutInflater inf = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);\r\n            view = inf.inflate(R.layout.group_items, null);\r\n        }\r\n\r\n        TextView heading = (TextView) view.findViewById(R.id.heading);\r\n        heading.setText(headerInfo.getName().trim());\r\n\r\n        return view;\r\n    }\r\n\r\n    @Override\r\n    public boolean hasStableIds() {\r\n        return true;\r\n    }\r\n\r\n    @Override\r\n    public boolean isChildSelectable(int groupPosition, int childPosition) {\r\n        return true;\r\n    }\r\n\r\n}<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p>Now run the App and you will see Team and player names displayed in ExpandableListView. This we have done using BaseExpandableListAdapter in Android.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>BaseExpandableListAdapter is a base class for the ExpandableListAdapter which is used to fill\u00a0the data and Views from some data (i.e. Arraylist, HashMap etc) to an ExpandableListView. For Creating a custom ExpandableListView we need to create a custom class and then extends\u00a0BaseExpandableListAdapter class in that class. An adapter is a bridge between UI component and data &hellip; <a href=\"https:\/\/abhiandroid.com\/ui\/baseexpandablelistadapter-example-android-studio.html\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">BaseExpandableListAdapter With Example In Android Studio<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":1473,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[62,1],"tags":[],"class_list":["post-1358","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-adapter","category-archieve"],"acf":[],"psp_head":"<title>BaseExpandableListAdapter With Example In Android Studio \u2013 Abhi Android<\/title>\r\n<meta name=\"description\" content=\"Tutorial on BaseExpandableListAdapter with step by step explanation using example in Android Studio. BaseExpandableListAdapter is a base class for the ExpandableListAdapter which is used to fill the data and Views from some data (i.e. Arraylist, HashMap etc) to an ExpandableListView.\" \/>\r\n<meta name=\"robots\" content=\"index,follow\" \/>\r\n<link rel=\"canonical\" href=\"https:\/\/abhiandroid.com\/ui\/baseexpandablelistadapter-example-android-studio.html\" \/>\r\n","_links":{"self":[{"href":"https:\/\/abhiandroid.com\/ui\/wp-json\/wp\/v2\/posts\/1358","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/abhiandroid.com\/ui\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/abhiandroid.com\/ui\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/abhiandroid.com\/ui\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/abhiandroid.com\/ui\/wp-json\/wp\/v2\/comments?post=1358"}],"version-history":[{"count":3,"href":"https:\/\/abhiandroid.com\/ui\/wp-json\/wp\/v2\/posts\/1358\/revisions"}],"predecessor-version":[{"id":2828,"href":"https:\/\/abhiandroid.com\/ui\/wp-json\/wp\/v2\/posts\/1358\/revisions\/2828"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/abhiandroid.com\/ui\/wp-json\/wp\/v2\/media\/1473"}],"wp:attachment":[{"href":"https:\/\/abhiandroid.com\/ui\/wp-json\/wp\/v2\/media?parent=1358"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/abhiandroid.com\/ui\/wp-json\/wp\/v2\/categories?post=1358"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/abhiandroid.com\/ui\/wp-json\/wp\/v2\/tags?post=1358"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}