Expandable listview with 4 Levels.

NiranjanKathrojiNiranjanKathroji USMember ✭✭
edited June 2018 in Xamarin.Android

Hi I have implemented three level expandable listview with following code with below link
A link.

But after implement, I understood my requirement is 4 level can somebody tell me how to implement 4 levels of the expandable listview.

Thanks
Niranjan.

Best Answer

  • NiranjanKathrojiNiranjanKathroji US ✭✭
    Accepted Answer

    My self-searched in the google and came up with the solution here it is

    Plan for multi level(i.e) is below
    plan

    Models for this

     public class GamificationHeaderTask
        {
            public string AsgnID { get; set; }
            public string StoreName { get; set; }
            public string LOB { get; set; }
            public string CollectionType { get; set; }    
        }
        public class TaskTopHeader
        {
            public string HeaderText { get; set; }
            public List<TaskSecondLevel> LstSecondLevel { get; set; }
        }
        public class TaskSecondLevel
        {
            public string SecondLevelText { get; set; }
            public List<TaskThirdLevel> LstThirdLevel { get; set; }
    
        }
        public class TaskThirdLevel
        {
            public string ThirdLevelText { get; set; }
            public List<GamificationHeaderTask> LstLastLevel { get; set; }
    
        }
    

    Activity implementation

    namespace ExpandMultiLevelNew
    {
        [Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true)]
        public class ThreeLevelExpandableListView : AppCompatActivity
        {
    
            private ExpandableListView expandableListView;
    
            protected override void OnCreate(Bundle savedInstanceState)
            {
                base.OnCreate(savedInstanceState);
    
                SetContentView(Resource.Layout.activity_main);
    
    
                expandableListView = (ExpandableListView)FindViewById(Resource.Id.mainList);
    
                List<TaskTopHeader> topHeaders = LoadHardCodedData();
    
                TaskListParentAdapter parentLevelAdapter = new TaskListParentAdapter(this, topHeaders);
                expandableListView.SetAdapter(parentLevelAdapter);
                expandableListView.TranscriptMode = TranscriptMode.Disabled;
                expandableListView.StackFromBottom = true;
    
                expandableListView.ChildClick += (s, e) =>
                {
    
                    var groupPos = e.GroupPosition;
                    var childPos = e.ChildPosition;
                    //string key = lstHeaders[groupPos];
                    //string value = lstHeaders[key][childPos];
                    //
    
                };
            }
    
            #region ParentLevel
    
            public class TaskListParentAdapter : BaseExpandableListAdapter
            {
                private Context context;
                List<TaskTopHeader> lstHeaders;
    
                public override int GroupCount => lstHeaders.Count;
    
                public override bool HasStableIds => true;
    
                public TaskListParentAdapter(Context context, List<TaskTopHeader> lstHeaders)
                {
                    this.context = context;
                    this.lstHeaders = lstHeaders;
                }
    
                public override Java.Lang.Object GetChild(int groupPosition, int childPosition)
                {
                    return childPosition;
                }
    
                public override long GetChildId(int groupPosition, int childPosition)
                {
                    return childPosition;
                }
    
                public override View GetChildView(int groupPosition, int childPosition, bool isLastChild, View convertView, ViewGroup parent)
                {
                    SecondLevelExpandableListView secondLevelELV = new SecondLevelExpandableListView(context);
    
                    List<TaskSecondLevel> subItems = lstHeaders[groupPosition].LstSecondLevel;
                    TaskListSecondLevelAdapter secondLevelAdapter = new TaskListSecondLevelAdapter(context, subItems);
                    secondLevelELV.SetAdapter(secondLevelAdapter);
                    //secondLevelELV.SetGroupIndicator(null);
                    return secondLevelELV;
                }
    
                public override int GetChildrenCount(int groupPosition)
                {
                    //return lstHeaders[groupPosition].LstSubItems.Count;
    
                    return 1;
                }
    
    
                public override Java.Lang.Object GetGroup(int groupPosition)
                {
                    return groupPosition;
                }
    
                public override long GetGroupId(int groupPosition)
                {
                    return groupPosition;
                }
    
                public override View GetGroupView(int groupPosition, bool isExpanded, View convertView, ViewGroup parent)
                {
                    if (convertView == null)
                    {
                        LayoutInflater inflater = (LayoutInflater)context.GetSystemService(Context.LayoutInflaterService);
                        convertView = inflater.Inflate(Resource.Layout.row_first, null);
                        TextView text = (TextView)convertView.FindViewById(Resource.Id.eventsListEventRowText);
    
                        TaskTopHeader header = lstHeaders[groupPosition];
    
                        text.Text = header.HeaderText;
                    }
                    else
                    {
                        TextView text = (TextView)convertView.FindViewById(Resource.Id.eventsListEventRowText);
                        TaskTopHeader header = lstHeaders[groupPosition];
                        text.Text = header.HeaderText;
    
                    }
                    return convertView;
                }
    
                public override bool IsChildSelectable(int groupPosition, int childPosition)
                {
                    return true;
                }
            }
            #endregion
    
    
            #region SecondLevelAdapter
    
            public class TaskListSecondLevelAdapter : BaseExpandableListAdapter
            {
                private Context context;
                private List<TaskSecondLevel> lstSubItems;
    
                public TaskListSecondLevelAdapter(Context context, List<TaskSecondLevel> lstSubItems)
                {
                    this.context = context;
                    this.lstSubItems = lstSubItems;
                }
    
                public override int GroupCount => lstSubItems.Count;
    
                public override bool HasStableIds => true;
    
                public override Java.Lang.Object GetChild(int groupPosition, int childPosition)
                {
                    return childPosition;
                }
    
                public override long GetChildId(int groupPosition, int childPosition)
                {
                    return childPosition;
                }
    
                public override int GetChildrenCount(int groupPosition)
                {
                    return 1;
                    // return lstSubItems[groupPosition].LstThirdLevel.Count;
    
                }
    
                public override View GetChildView(int groupPosition, int childPosition, bool isLastChild, View convertView, ViewGroup parent)
                {
                    ThirdLevelExpandableListView secondLevelELV = new ThirdLevelExpandableListView(context);
    
                    List<TaskThirdLevel> subItems = lstSubItems[groupPosition].LstThirdLevel;
                    TaskListThirdLevelAdapter secondLevelAdapter = new TaskListThirdLevelAdapter(context, subItems);
                    secondLevelELV.SetAdapter(secondLevelAdapter);
                    //secondLevelELV.SetGroupIndicator(null);
                    return secondLevelELV;
                }
    
                public override Java.Lang.Object GetGroup(int groupPosition)
                {
                    return groupPosition;
                }
    
                public override long GetGroupId(int groupPosition)
                {
                    return groupPosition;
                }
    
                public override View GetGroupView(int groupPosition, bool isExpanded, View convertView, ViewGroup parent)
                {
                    TaskSecondLevel subItem = lstSubItems[groupPosition];
    
                    if (convertView == null)
                    {
                        LayoutInflater inflater = (LayoutInflater)context.GetSystemService(Context.LayoutInflaterService);
                        convertView = inflater.Inflate(Resource.Layout.row_second, null);
                        TextView text = (TextView)convertView.FindViewById(Resource.Id.eventsListEventRowText);
                        text.Text = subItem.SecondLevelText;
                    }
                    else
                    {
                        TextView text = (TextView)convertView.FindViewById(Resource.Id.eventsListEventRowText);
                        text.Text = subItem.SecondLevelText;
                    }
                    return convertView;
                }
    
                public override bool IsChildSelectable(int groupPosition, int childPosition)
                {
                    return true;
                }
            }
            #endregion
    
    
            #region ThirdLevelAdapter
    
            public class TaskListThirdLevelAdapter : BaseExpandableListAdapter
            {
                private Context context;
                List<TaskThirdLevel> lstSubItems;
    
                public TaskListThirdLevelAdapter(Context context, List<TaskThirdLevel> lstSubItems)
                {
                    this.context = context;
                    this.lstSubItems = lstSubItems;
                }
    
                public override int GroupCount => lstSubItems.Count;
    
                public override bool HasStableIds => true;
    
                public override Java.Lang.Object GetChild(int groupPosition, int childPosition)
                {
                    return childPosition;
                }
    
                public override long GetChildId(int groupPosition, int childPosition)
                {
                    return childPosition;
                }
    
                public override int GetChildrenCount(int groupPosition)
                {
                    return lstSubItems[groupPosition].LstLastLevel.Count;
    
                }
    
                public override View GetChildView(int groupPosition, int childPosition, bool isLastChild, View convertView, ViewGroup parent)
                {
                    if (convertView == null)
                    {
                        LayoutInflater inflater = (LayoutInflater)context.GetSystemService(Context.LayoutInflaterService);
                        convertView = inflater.Inflate(Resource.Layout.row_four, null);
                        TextView text = (TextView)convertView.FindViewById(Resource.Id.eventsListEventRowText);
    
                        string result = lstSubItems[groupPosition].LstLastLevel[childPosition].AsgnID;
    
                        text.Text = result;
    
                        convertView.Click += (s, e) =>
                        {
                            var grp = groupPosition;
                            var childPos = childPosition;
    
    
    
    
                        };
                    }
                    else
                    {
                        TextView text = (TextView)convertView.FindViewById(Resource.Id.eventsListEventRowText);
                        string result = lstSubItems[groupPosition].LstLastLevel[childPosition].AsgnID;
                        text.Text = result;
    
                    }
                    return convertView;
                }
    
                public override Java.Lang.Object GetGroup(int groupPosition)
                {
                    return groupPosition;
                }
    
                public override long GetGroupId(int groupPosition)
                {
                    return groupPosition;
                }
    
                public override View GetGroupView(int groupPosition, bool isExpanded, View convertView, ViewGroup parent)
                {
                    TaskThirdLevel subItem = lstSubItems[groupPosition];
    
                    if (convertView == null)
                    {
                        LayoutInflater inflater = (LayoutInflater)context.GetSystemService(Context.LayoutInflaterService);
                        convertView = inflater.Inflate(Resource.Layout.row_third, null);
                        TextView text = (TextView)convertView.FindViewById(Resource.Id.eventsListEventRowText);
                        text.Text = subItem.ThirdLevelText;
                    }
                    else
                    {
                        TextView text = (TextView)convertView.FindViewById(Resource.Id.eventsListEventRowText);
                        text.Text = subItem.ThirdLevelText;
                    }
                    return convertView;
                }
    
                public override bool IsChildSelectable(int groupPosition, int childPosition)
                {
                    return true;
                }
            }
            #endregion
    
    
    
            #region SecondLevelExpandableListView
    
            public class SecondLevelExpandableListView : ExpandableListView
            {
                public SecondLevelExpandableListView(Context context) : base(context)
                {
    
                }
    
                protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
                {
                    //999999 is a size in pixels. ExpandableListView requires a maximum height in order to do measurement calculations. 
                    heightMeasureSpec = MeasureSpec.MakeMeasureSpec(99999, MeasureSpecMode.Exactly);
                    base.OnMeasure(widthMeasureSpec, heightMeasureSpec);
                }
            }
    
    
            #endregion
    
    
            #region ThirdLevelExpandableListView
    
            public class ThirdLevelExpandableListView : ExpandableListView
            {
                public ThirdLevelExpandableListView(Context context) : base(context)
                {
    
                }
    
                protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
                {
                    //999999 is a size in pixels. ExpandableListView requires a maximum height in order to do measurement calculations. 
                    heightMeasureSpec = MeasureSpec.MakeMeasureSpec(999999, MeasureSpecMode.AtMost);
                    base.OnMeasure(widthMeasureSpec, heightMeasureSpec);
                }
            }
    
    
            #endregion
    
    
    
    
    
            private List<TaskTopHeader> LoadHardCodedData()
            {
                List<GamificationHeaderTask> allHeaderTasks = new List<GamificationHeaderTask>();
    
    
                #region Load hard coded data
                allHeaderTasks.Add(new GamificationHeaderTask
                {
                    AsgnID = "1520",
                    LOB = "RMS",
                    CollectionType = "RA",
                    StoreName = "One"
    
                });
                allHeaderTasks.Add(new GamificationHeaderTask
                {
                    AsgnID = "1522",
                    LOB = "RMS",
                    CollectionType = "RA",
                    StoreName = "One"
    
                });
    
    
                allHeaderTasks.Add(new GamificationHeaderTask
                {
                    AsgnID = "2185",
                    LOB = "RMS",
                    CollectionType = "SFA",
                    StoreName = "One"
    
                });
    
    
    
                allHeaderTasks.Add(new GamificationHeaderTask
                {
                    AsgnID = "2182",
                    LOB = "RMS",
                    CollectionType = "RA",
                    StoreName = "SONALIKA STATIONERY RA"
    
                });
    
                allHeaderTasks.Add(new GamificationHeaderTask
                {
                    AsgnID = "2183",
                    LOB = "RMS",
                    CollectionType = "RA",
                    StoreName = "SHARWAN DOODH RA"
    
                });
    
                allHeaderTasks.Add(new GamificationHeaderTask
                {
                    AsgnID = "2183",
                    LOB = "RMS",
                    CollectionType = "RA",
                    StoreName = "SHARWAN DOODH RA"
    
                });
    
                allHeaderTasks.Add(new GamificationHeaderTask
                {
                    AsgnID = "3568",
                    LOB = "RMS",
                    CollectionType = "RES",
                    StoreName = "xxxx"
    
                });
    
    
                #endregion
    
                List<TaskTopHeader> lstTopHeader = new List<TaskTopHeader>();
    
                //RMS group
                var groupByLob = allHeaderTasks.GroupBy(x => x.LOB);
    
                foreach (var topLevel in groupByLob)
                {
                    TaskTopHeader header = new TaskTopHeader();
                    header.HeaderText = topLevel.Key;
    
                    List<TaskSecondLevel> lstSecondLevel = new List<TaskSecondLevel>();
                    header.LstSecondLevel = lstSecondLevel;
    
                    //RA, SFA, RES group
                    var grpTopLevel = topLevel.GroupBy(x => x.CollectionType);
    
                    foreach (var secondLevel in grpTopLevel)
                    {
                        TaskSecondLevel secondLvl = new TaskSecondLevel();
                        secondLvl.SecondLevelText = secondLevel.Key;
    
                        List<TaskThirdLevel> lstThirdLevel = new List<TaskThirdLevel>();
                        secondLvl.LstThirdLevel = lstThirdLevel;
    
                        //Store Name group
                        var grpSecondLevle = secondLevel.GroupBy(x => x.StoreName);
    
                        foreach (var item in grpSecondLevle)
                        {
                            TaskThirdLevel thirdLevel = new TaskThirdLevel();
                            thirdLevel.ThirdLevelText = item.Key;
                            thirdLevel.LstLastLevel = item.ToList();
                            lstThirdLevel.Add(thirdLevel);
                        }
    
                        lstSecondLevel.Add(secondLvl);
                    }
    
                    lstTopHeader.Add(header);
    
    
                }
                return lstTopHeader;
            }
        }
    
    
    }
    

    activity_main.xml

    activity_main

    row_first.xml and row_four.xml

    row_second.xml

    row_third.xml

    dimens.xml

    Jut copy paste above code and write this images as xml files than code will work fine.

Answers

  • NiranjanKathrojiNiranjanKathroji USMember ✭✭
    Accepted Answer

    My self-searched in the google and came up with the solution here it is

    Plan for multi level(i.e) is below
    plan

    Models for this

     public class GamificationHeaderTask
        {
            public string AsgnID { get; set; }
            public string StoreName { get; set; }
            public string LOB { get; set; }
            public string CollectionType { get; set; }    
        }
        public class TaskTopHeader
        {
            public string HeaderText { get; set; }
            public List<TaskSecondLevel> LstSecondLevel { get; set; }
        }
        public class TaskSecondLevel
        {
            public string SecondLevelText { get; set; }
            public List<TaskThirdLevel> LstThirdLevel { get; set; }
    
        }
        public class TaskThirdLevel
        {
            public string ThirdLevelText { get; set; }
            public List<GamificationHeaderTask> LstLastLevel { get; set; }
    
        }
    

    Activity implementation

    namespace ExpandMultiLevelNew
    {
        [Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true)]
        public class ThreeLevelExpandableListView : AppCompatActivity
        {
    
            private ExpandableListView expandableListView;
    
            protected override void OnCreate(Bundle savedInstanceState)
            {
                base.OnCreate(savedInstanceState);
    
                SetContentView(Resource.Layout.activity_main);
    
    
                expandableListView = (ExpandableListView)FindViewById(Resource.Id.mainList);
    
                List<TaskTopHeader> topHeaders = LoadHardCodedData();
    
                TaskListParentAdapter parentLevelAdapter = new TaskListParentAdapter(this, topHeaders);
                expandableListView.SetAdapter(parentLevelAdapter);
                expandableListView.TranscriptMode = TranscriptMode.Disabled;
                expandableListView.StackFromBottom = true;
    
                expandableListView.ChildClick += (s, e) =>
                {
    
                    var groupPos = e.GroupPosition;
                    var childPos = e.ChildPosition;
                    //string key = lstHeaders[groupPos];
                    //string value = lstHeaders[key][childPos];
                    //
    
                };
            }
    
            #region ParentLevel
    
            public class TaskListParentAdapter : BaseExpandableListAdapter
            {
                private Context context;
                List<TaskTopHeader> lstHeaders;
    
                public override int GroupCount => lstHeaders.Count;
    
                public override bool HasStableIds => true;
    
                public TaskListParentAdapter(Context context, List<TaskTopHeader> lstHeaders)
                {
                    this.context = context;
                    this.lstHeaders = lstHeaders;
                }
    
                public override Java.Lang.Object GetChild(int groupPosition, int childPosition)
                {
                    return childPosition;
                }
    
                public override long GetChildId(int groupPosition, int childPosition)
                {
                    return childPosition;
                }
    
                public override View GetChildView(int groupPosition, int childPosition, bool isLastChild, View convertView, ViewGroup parent)
                {
                    SecondLevelExpandableListView secondLevelELV = new SecondLevelExpandableListView(context);
    
                    List<TaskSecondLevel> subItems = lstHeaders[groupPosition].LstSecondLevel;
                    TaskListSecondLevelAdapter secondLevelAdapter = new TaskListSecondLevelAdapter(context, subItems);
                    secondLevelELV.SetAdapter(secondLevelAdapter);
                    //secondLevelELV.SetGroupIndicator(null);
                    return secondLevelELV;
                }
    
                public override int GetChildrenCount(int groupPosition)
                {
                    //return lstHeaders[groupPosition].LstSubItems.Count;
    
                    return 1;
                }
    
    
                public override Java.Lang.Object GetGroup(int groupPosition)
                {
                    return groupPosition;
                }
    
                public override long GetGroupId(int groupPosition)
                {
                    return groupPosition;
                }
    
                public override View GetGroupView(int groupPosition, bool isExpanded, View convertView, ViewGroup parent)
                {
                    if (convertView == null)
                    {
                        LayoutInflater inflater = (LayoutInflater)context.GetSystemService(Context.LayoutInflaterService);
                        convertView = inflater.Inflate(Resource.Layout.row_first, null);
                        TextView text = (TextView)convertView.FindViewById(Resource.Id.eventsListEventRowText);
    
                        TaskTopHeader header = lstHeaders[groupPosition];
    
                        text.Text = header.HeaderText;
                    }
                    else
                    {
                        TextView text = (TextView)convertView.FindViewById(Resource.Id.eventsListEventRowText);
                        TaskTopHeader header = lstHeaders[groupPosition];
                        text.Text = header.HeaderText;
    
                    }
                    return convertView;
                }
    
                public override bool IsChildSelectable(int groupPosition, int childPosition)
                {
                    return true;
                }
            }
            #endregion
    
    
            #region SecondLevelAdapter
    
            public class TaskListSecondLevelAdapter : BaseExpandableListAdapter
            {
                private Context context;
                private List<TaskSecondLevel> lstSubItems;
    
                public TaskListSecondLevelAdapter(Context context, List<TaskSecondLevel> lstSubItems)
                {
                    this.context = context;
                    this.lstSubItems = lstSubItems;
                }
    
                public override int GroupCount => lstSubItems.Count;
    
                public override bool HasStableIds => true;
    
                public override Java.Lang.Object GetChild(int groupPosition, int childPosition)
                {
                    return childPosition;
                }
    
                public override long GetChildId(int groupPosition, int childPosition)
                {
                    return childPosition;
                }
    
                public override int GetChildrenCount(int groupPosition)
                {
                    return 1;
                    // return lstSubItems[groupPosition].LstThirdLevel.Count;
    
                }
    
                public override View GetChildView(int groupPosition, int childPosition, bool isLastChild, View convertView, ViewGroup parent)
                {
                    ThirdLevelExpandableListView secondLevelELV = new ThirdLevelExpandableListView(context);
    
                    List<TaskThirdLevel> subItems = lstSubItems[groupPosition].LstThirdLevel;
                    TaskListThirdLevelAdapter secondLevelAdapter = new TaskListThirdLevelAdapter(context, subItems);
                    secondLevelELV.SetAdapter(secondLevelAdapter);
                    //secondLevelELV.SetGroupIndicator(null);
                    return secondLevelELV;
                }
    
                public override Java.Lang.Object GetGroup(int groupPosition)
                {
                    return groupPosition;
                }
    
                public override long GetGroupId(int groupPosition)
                {
                    return groupPosition;
                }
    
                public override View GetGroupView(int groupPosition, bool isExpanded, View convertView, ViewGroup parent)
                {
                    TaskSecondLevel subItem = lstSubItems[groupPosition];
    
                    if (convertView == null)
                    {
                        LayoutInflater inflater = (LayoutInflater)context.GetSystemService(Context.LayoutInflaterService);
                        convertView = inflater.Inflate(Resource.Layout.row_second, null);
                        TextView text = (TextView)convertView.FindViewById(Resource.Id.eventsListEventRowText);
                        text.Text = subItem.SecondLevelText;
                    }
                    else
                    {
                        TextView text = (TextView)convertView.FindViewById(Resource.Id.eventsListEventRowText);
                        text.Text = subItem.SecondLevelText;
                    }
                    return convertView;
                }
    
                public override bool IsChildSelectable(int groupPosition, int childPosition)
                {
                    return true;
                }
            }
            #endregion
    
    
            #region ThirdLevelAdapter
    
            public class TaskListThirdLevelAdapter : BaseExpandableListAdapter
            {
                private Context context;
                List<TaskThirdLevel> lstSubItems;
    
                public TaskListThirdLevelAdapter(Context context, List<TaskThirdLevel> lstSubItems)
                {
                    this.context = context;
                    this.lstSubItems = lstSubItems;
                }
    
                public override int GroupCount => lstSubItems.Count;
    
                public override bool HasStableIds => true;
    
                public override Java.Lang.Object GetChild(int groupPosition, int childPosition)
                {
                    return childPosition;
                }
    
                public override long GetChildId(int groupPosition, int childPosition)
                {
                    return childPosition;
                }
    
                public override int GetChildrenCount(int groupPosition)
                {
                    return lstSubItems[groupPosition].LstLastLevel.Count;
    
                }
    
                public override View GetChildView(int groupPosition, int childPosition, bool isLastChild, View convertView, ViewGroup parent)
                {
                    if (convertView == null)
                    {
                        LayoutInflater inflater = (LayoutInflater)context.GetSystemService(Context.LayoutInflaterService);
                        convertView = inflater.Inflate(Resource.Layout.row_four, null);
                        TextView text = (TextView)convertView.FindViewById(Resource.Id.eventsListEventRowText);
    
                        string result = lstSubItems[groupPosition].LstLastLevel[childPosition].AsgnID;
    
                        text.Text = result;
    
                        convertView.Click += (s, e) =>
                        {
                            var grp = groupPosition;
                            var childPos = childPosition;
    
    
    
    
                        };
                    }
                    else
                    {
                        TextView text = (TextView)convertView.FindViewById(Resource.Id.eventsListEventRowText);
                        string result = lstSubItems[groupPosition].LstLastLevel[childPosition].AsgnID;
                        text.Text = result;
    
                    }
                    return convertView;
                }
    
                public override Java.Lang.Object GetGroup(int groupPosition)
                {
                    return groupPosition;
                }
    
                public override long GetGroupId(int groupPosition)
                {
                    return groupPosition;
                }
    
                public override View GetGroupView(int groupPosition, bool isExpanded, View convertView, ViewGroup parent)
                {
                    TaskThirdLevel subItem = lstSubItems[groupPosition];
    
                    if (convertView == null)
                    {
                        LayoutInflater inflater = (LayoutInflater)context.GetSystemService(Context.LayoutInflaterService);
                        convertView = inflater.Inflate(Resource.Layout.row_third, null);
                        TextView text = (TextView)convertView.FindViewById(Resource.Id.eventsListEventRowText);
                        text.Text = subItem.ThirdLevelText;
                    }
                    else
                    {
                        TextView text = (TextView)convertView.FindViewById(Resource.Id.eventsListEventRowText);
                        text.Text = subItem.ThirdLevelText;
                    }
                    return convertView;
                }
    
                public override bool IsChildSelectable(int groupPosition, int childPosition)
                {
                    return true;
                }
            }
            #endregion
    
    
    
            #region SecondLevelExpandableListView
    
            public class SecondLevelExpandableListView : ExpandableListView
            {
                public SecondLevelExpandableListView(Context context) : base(context)
                {
    
                }
    
                protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
                {
                    //999999 is a size in pixels. ExpandableListView requires a maximum height in order to do measurement calculations. 
                    heightMeasureSpec = MeasureSpec.MakeMeasureSpec(99999, MeasureSpecMode.Exactly);
                    base.OnMeasure(widthMeasureSpec, heightMeasureSpec);
                }
            }
    
    
            #endregion
    
    
            #region ThirdLevelExpandableListView
    
            public class ThirdLevelExpandableListView : ExpandableListView
            {
                public ThirdLevelExpandableListView(Context context) : base(context)
                {
    
                }
    
                protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
                {
                    //999999 is a size in pixels. ExpandableListView requires a maximum height in order to do measurement calculations. 
                    heightMeasureSpec = MeasureSpec.MakeMeasureSpec(999999, MeasureSpecMode.AtMost);
                    base.OnMeasure(widthMeasureSpec, heightMeasureSpec);
                }
            }
    
    
            #endregion
    
    
    
    
    
            private List<TaskTopHeader> LoadHardCodedData()
            {
                List<GamificationHeaderTask> allHeaderTasks = new List<GamificationHeaderTask>();
    
    
                #region Load hard coded data
                allHeaderTasks.Add(new GamificationHeaderTask
                {
                    AsgnID = "1520",
                    LOB = "RMS",
                    CollectionType = "RA",
                    StoreName = "One"
    
                });
                allHeaderTasks.Add(new GamificationHeaderTask
                {
                    AsgnID = "1522",
                    LOB = "RMS",
                    CollectionType = "RA",
                    StoreName = "One"
    
                });
    
    
                allHeaderTasks.Add(new GamificationHeaderTask
                {
                    AsgnID = "2185",
                    LOB = "RMS",
                    CollectionType = "SFA",
                    StoreName = "One"
    
                });
    
    
    
                allHeaderTasks.Add(new GamificationHeaderTask
                {
                    AsgnID = "2182",
                    LOB = "RMS",
                    CollectionType = "RA",
                    StoreName = "SONALIKA STATIONERY RA"
    
                });
    
                allHeaderTasks.Add(new GamificationHeaderTask
                {
                    AsgnID = "2183",
                    LOB = "RMS",
                    CollectionType = "RA",
                    StoreName = "SHARWAN DOODH RA"
    
                });
    
                allHeaderTasks.Add(new GamificationHeaderTask
                {
                    AsgnID = "2183",
                    LOB = "RMS",
                    CollectionType = "RA",
                    StoreName = "SHARWAN DOODH RA"
    
                });
    
                allHeaderTasks.Add(new GamificationHeaderTask
                {
                    AsgnID = "3568",
                    LOB = "RMS",
                    CollectionType = "RES",
                    StoreName = "xxxx"
    
                });
    
    
                #endregion
    
                List<TaskTopHeader> lstTopHeader = new List<TaskTopHeader>();
    
                //RMS group
                var groupByLob = allHeaderTasks.GroupBy(x => x.LOB);
    
                foreach (var topLevel in groupByLob)
                {
                    TaskTopHeader header = new TaskTopHeader();
                    header.HeaderText = topLevel.Key;
    
                    List<TaskSecondLevel> lstSecondLevel = new List<TaskSecondLevel>();
                    header.LstSecondLevel = lstSecondLevel;
    
                    //RA, SFA, RES group
                    var grpTopLevel = topLevel.GroupBy(x => x.CollectionType);
    
                    foreach (var secondLevel in grpTopLevel)
                    {
                        TaskSecondLevel secondLvl = new TaskSecondLevel();
                        secondLvl.SecondLevelText = secondLevel.Key;
    
                        List<TaskThirdLevel> lstThirdLevel = new List<TaskThirdLevel>();
                        secondLvl.LstThirdLevel = lstThirdLevel;
    
                        //Store Name group
                        var grpSecondLevle = secondLevel.GroupBy(x => x.StoreName);
    
                        foreach (var item in grpSecondLevle)
                        {
                            TaskThirdLevel thirdLevel = new TaskThirdLevel();
                            thirdLevel.ThirdLevelText = item.Key;
                            thirdLevel.LstLastLevel = item.ToList();
                            lstThirdLevel.Add(thirdLevel);
                        }
    
                        lstSecondLevel.Add(secondLvl);
                    }
    
                    lstTopHeader.Add(header);
    
    
                }
                return lstTopHeader;
            }
        }
    
    
    }
    

    activity_main.xml

    activity_main

    row_first.xml and row_four.xml

    row_second.xml

    row_third.xml

    dimens.xml

    Jut copy paste above code and write this images as xml files than code will work fine.

Sign In or Register to comment.