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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:03:17+00:00 2026-06-18T01:03:17+00:00

I am in search of implementing fragments with expandable list view . After searching

  • 0

I am in search of implementing fragments with expandable list view . After searching i found a class that implements expandable listview fragment on https://gist.github.com/1316903 . But i have no idea how to use it. Please help me. I tried list fragments ,but i have no idea about using fragments with expandable list view thanks in advance.

  • 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-18T01:03:18+00:00Added an answer on June 18, 2026 at 1:03 am

    Here is what I got in MonoDroid/C#. I had to strip away some code (for confidentiality), but it should be mostly complete.

    This implementation can support distinct child-views, where each group contains a specific child-type that is the same throughout that group. However, you can mix child-types within a group, and can even have different group-types (which just changes the group header really; I use the same group-type for both groups, and use the group’s position to determine the child-type – so group[0] contains children of ExpandableListChild1 and group[1] of ExpandableListChild2 – as is the intended use).

    The child-types here only differ by their background color (for simplicity’s sake), however these views can be any view you require, including custom views. Just make a corresponding ExpandListChild subclass for whatever view you need. Also, the base class ExpandListChildAbs can be whatever you need to suit your app. If you only have one child type, a base class isn’t necessary, however if there are two or more then you need some sort of base class both children-types can subclass from to support the polymorphism within the BaseExpandableListAdapter method getChild and related methods.

    [Activity(
        Label = "ExpandableListView in a Fragment", 
        Theme = "@android:style/Theme.NoTitleBar", 
        MainLauncher = false,
        ConfigurationChanges = ConfigChanges.KeyboardHidden,
        WindowSoftInputMode = SoftInput.AdjustPan | SoftInput.StateHidden)] 
    
    public class Fragment1 : Fragment
    {
        private ViewGroup _thisView;       
    
        private Bundle _bundle;
        private LayoutInflater _inflater;
        private ViewGroup _container;
    
        public override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);          
    
            _bundle = bundle;
            _model = Model;
        }
    
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle)
        {
            base.OnCreateView(inflater, container, bundle);
    
            _inflater = inflater;
            _container = container;
            _bundle = bundle;
    
             Render();
    
            return _thisView;
        }        
    
        public override void OnAttach(Activity activity)
        {
            base.OnAttach(activity);
    
            _dialogListener = (IDialogWindow)activity;
        }                
    
        //public Context LocalContext { get; set; }
    
        public override void OnActivityCreated(Bundle savedInstanceState)
        {
            base.OnActivityCreated(savedInstanceState);            
        }
    
        public override void OnViewCreated(View view, Bundle savedInstanceState)
        {
            base.OnViewCreated(view, savedInstanceState);            
        }
    
        public override void Render()
        {   
            _thisView = (ViewGroup)_inflater.Inflate(Resource.Layout.MainLayout, _container, false);
    
            ExpandableListView elvParcelInfo = _thisView.FindViewById<ExpandableListView>(Resource.Id.elv_parcel_info);
            List<ExpandListGroup> expandListItems = SetStandardGroups();
            ExpandListAdapter expandListAdapter = new ExpandListAdapter(Activity.ApplicationContext, expandListItems);
            elvParcelInfo.SetAdapter(expandListAdapter);
        }
    
        public List<ExpandListGroup> SetStandardGroups()
        {
            List<ExpandListChild1> childern1 = new List<ExpandListChild1>();
    
            for (int i = 0; i < 20; i++)
            {
                ExpandListChild1 child1 = new ExpandListChild1();
                child1.Name = "child1 #" + i.ToString();
                child1.Tag = null;
    
                childern1.Add(child1);
            }
    
            ExpandListGroup group1 = new ExpandListGroup();
            group1.Name = "Comedy";
            //group1.Items = childern1;
            group1.Items = new List<ExpandListChildAbs>();
            foreach (ExpandListChild1 child1 in childern1)
            {
                group1.Items.Add(child1);
            }
    
            /////////////////////////////////////////////////////////////
    
            List<ExpandListChild2> childern2 = new List<ExpandListChild2>();
    
            for (int i = 0; i < 20; i++)
            {
                ExpandListChild2 child2 = new ExpandListChild2();
                child2.Name = "child2 #" + i.ToString();
                child2.Tag = null;
    
                childern2.Add(child2);
            }
    
            ExpandListGroup group2 = new ExpandListGroup();
            group2.Name = "Action";
            //group2.Items = childern2;
            group2.Items = new List<ExpandListChildAbs>();
            foreach (ExpandListChild2 child2 in childern2)
            {
                group2.Items.Add(child2);
            }
    
            /////////////////////////////////////////////////////////////
    
            List<ExpandListGroup> groups = new List<ExpandListGroup>();
            groups.Add(group1);
            groups.Add(group2);
    
            return groups;
        }
    
        public abstract class ExpandListChildAbs : Java.Lang.Object
        {
            public abstract String Name { get; set; }
            public abstract String Tag { get; set; }
        }
    
        public class ExpandListChild1 : ExpandListChildAbs
        {
            public override String Name { get; set; }
            public override String Tag { get; set; }
        }
    
        public class ExpandListChild2 : ExpandListChildAbs
        {
            public override String Name { get; set; }
            public override String Tag { get; set; }
        }
    
        public class ExpandListGroup : Java.Lang.Object
        {
            public String Name { get; set; }
            public List<ExpandListChildAbs> Items { get; set; }
        }
    
        public class ExpandListAdapter : BaseExpandableListAdapter
        {
            private enum ChildTypes { ChildType1, ChildType2 }
            private Context context;
            private List<ExpandListGroup> groups;
    
            public ExpandListAdapter(Context context, List<ExpandListGroup> groups) 
            {
                this.context = context;
                this.groups = groups;
            }
    
            public void AddItem(ExpandListChildAbs item, ExpandListGroup group) 
            {                              
                if (!groups.Contains(group)) 
                {
                    groups.Add(group);
                }
    
                int index = groups.IndexOf(group);
    
                List<ExpandListChildAbs> ch = groups[index].Items;
    
                ch.Add(item);
                groups[index].Items = ch;
            }
    
            public override bool HasStableIds
            {
                get { return true; }
            }
    
            public override bool IsChildSelectable(int arg0, int arg1)
            {
                return true;
            }
    
            //______________________________________________________________________________________________________
            // Get Child Methods
            //______________________________________________________________________________________________________
    
            public override long GetChildId(int groupPosition, int childPosition)
            {
                return childPosition;                
            }
    
            public override int GetChildrenCount(int groupPosition)
            {
                List<ExpandListChildAbs> chList = groups[groupPosition].Items;               
    
                return chList.Count;
            }
    
            public override int ChildTypeCount
            {
                get { return Enum.GetNames(typeof(ChildTypes)).Length; }
            }
    
            public override int GetChildType(int groupPosition, int childPosition)
            {   
                //return base.GetChildType(groupPosition, childPosition);
    
                if (groupPosition == 0)
                {
                    return (int)ChildTypes.ChildType1;
                }
    
                if (groupPosition == 1)
                {
                    return (int)ChildTypes.ChildType2;
                }
    
                return 0;
            }
    
            public override Java.Lang.Object GetChild(int groupPosition, int childPosition)
            {
                List<ExpandListChildAbs> chList = groups[groupPosition].Items;
    
                return chList[childPosition];
            }
    
            public override View GetChildView(int groupPosition, int childPosition, bool isLastChild, View view, ViewGroup parent)
            {
                int ChildType = GetChildType(groupPosition, childPosition);
    
                if (ChildType == (int)ChildTypes.ChildType1)
                {
                    return GetChildView_ChildType1(groupPosition, childPosition, isLastChild, view, parent);
                }
    
                if (ChildType == (int)ChildTypes.ChildType2)
                {
                    return GetChildView_ChildType2(groupPosition, childPosition, isLastChild, view, parent);
                }
    
                return null;
            }
    
            private View GetChildView_ChildType1(int groupPosition, int childPosition, bool isLastChild, View view, ViewGroup parent)
            {   
                ExpandListChild1 child1 = (ExpandListChild1)GetChild(groupPosition, childPosition);
    
                if (view == null)
                {
                    LayoutInflater infalInflater = (LayoutInflater)context.GetSystemService(Context.LayoutInflaterService);
    
                    view = infalInflater.Inflate(Resource.Layout.ExpandList_ChildItem1, null);
                }
    
                TextView tv = view.FindViewById<TextView>(Resource.Id.tvChild1);
    
                tv.Text = child1.Name;
                tv.Tag = child1.Tag;
    
                return view;
            }
    
            private View GetChildView_ChildType2(int groupPosition, int childPosition, bool isLastChild, View view, ViewGroup parent)
            {
                ExpandListChild2 child2 = (ExpandListChild2)GetChild(groupPosition, childPosition);
    
                if (view == null)
                {
                    LayoutInflater infalInflater = (LayoutInflater)context.GetSystemService(Context.LayoutInflaterService);
    
                    view = infalInflater.Inflate(Resource.Layout.ExpandList_ChildItem2, null);
                }
    
                TextView tv = view.FindViewById<TextView>(Resource.Id.tvChild2);
    
                tv.Text = child2.Name;
                tv.Tag = child2.Tag;
    
                return view;
            }
    
            //________________________________________________________________________________________________________
    
    
            //______________________________________________________________________________________________________
            // Get Group Methods
            //______________________________________________________________________________________________________
    
            public override long GetGroupId(int groupPosition)
            {
                return groupPosition;
            }
    
            public override int GroupCount
            {
                get { return groups.Count; }
            }
    
            public override int GroupTypeCount 
            { 
                get { return base.GroupTypeCount; } 
            }
    
            public override int GetGroupType(int groupPosition)
            {
                return base.GetGroupType(groupPosition);
            }
    
            public override Java.Lang.Object GetGroup(int groupPosition)
            {
                return groups[groupPosition];
            }
    
            public override View GetGroupView(int groupPosition, bool isLastChild, View view, ViewGroup parent) 
            {
                ExpandListGroup group = (ExpandListGroup) GetGroup(groupPosition);
    
                if (view == null) 
                {
                    LayoutInflater inf = (LayoutInflater) context.GetSystemService(Context.LayoutInflaterService);
    
                    view = inf.Inflate(Resource.Layout.ExpandList_GroupItem, null);
                }
    
                TextView tv = view.FindViewById<TextView>(Resource.Id.tvGroup);
    
                tv.Text = group.Name;
    
                return view;
            }
    
            //________________________________________________________________________________________________________
        }      
    }
    

    MainLayout

    <?xml version="1.0" encoding="utf-8"?>
    
    <LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/ll_left_parcel"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="vertical"
      android:background="#FF8F8D8F">     
    
      <ExpandableListView
        android:id="@+id/elv_parcel_info"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#FFCFCDCF"
        android:groupIndicator="@null"/>  
    
    </LinearLayout>
    

    ExpandList_GroupItem

    <?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="55dip"
        android:background="#FF00AA55"
        android:orientation="vertical" >
    
    
      <TextView
          android:id="@+id/tvGroup"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_marginRight="15dp"
          android:textColor="#FF000000"
          android:textSize="17dip" />
    
    </LinearLayout>
    

    ExpandList_ChildItem1

    <?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="55dip"
        android:background="#FF8800CC"
        android:orientation="vertical" >
    
      <TextView
          android:id="@+id/tvChild1"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:textColor="#FF000000"
          android:textSize="17dip" />
    
    </LinearLayout>
    

    ExpandList_ChildItem2

    <?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="55dip"
        android:background="#FFAA00FF"
        android:orientation="vertical" >
    
      <TextView
          android:id="@+id/tvChild2"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:textColor="#FF000000"
          android:textSize="17dip" />
    
    </LinearLayout>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm implementing a search in my website, and would like to support searching for
I am looking for a means of implementing a Search routine/page that I can
I am new to ruby and am having trouble implementing the view for search
I'm implementing a search feature for an app that uses entity framework. There are
I am implementing a child borderless search results window that floats under a NSSearchField
I'm implementing a search field that filters a UITableView according to the text the
I am implementing search bar in my iphone app to apply searching on array
I'm tasked with implementing a search function that will search through several large (couple
I am implementing search feature for a news website. On that website ,users submit
I am implementing a Search autocomplete. I’d like to return a list of results

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.