-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExpandableListAdapter.cs
95 lines (88 loc) · 3.23 KB
/
ExpandableListAdapter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
namespace ImageSlider.NoticeBoard
{
public class ExpandableListAdapter : BaseExpandableListAdapter
{
private Activity _context;
private List<string> _listDataHeader; // header titles
// child data in format of header title, child title
private Dictionary<string, List<string>> _listDataChild;
public ExpandableListAdapter(Activity context, List<string> listDataHeader, Dictionary<String, List<string>> listChildData)
{
_context = context;
_listDataHeader = listDataHeader;
_listDataChild = listChildData;
}
//for cchild item view
public override Java.Lang.Object GetChild(int groupPosition, int childPosition)
{
return _listDataChild[_listDataHeader[groupPosition]][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)
{
string childText = (string)GetChild(groupPosition, childPosition);
if (convertView == null)
{
convertView = _context.LayoutInflater.Inflate(Resource.Layout.ListItemCustomLayout, null);
}
TextView txtListChild = (TextView)convertView.FindViewById(Resource.Id.lblListItem);
txtListChild.Text = childText;
return convertView;
}
public override int GetChildrenCount(int groupPosition)
{
return _listDataChild[_listDataHeader[groupPosition]].Count;
}
//For header view
public override Java.Lang.Object GetGroup(int groupPosition)
{
return _listDataHeader[groupPosition];
}
public override int GroupCount
{
get
{
return _listDataHeader.Count;
}
}
public override long GetGroupId(int groupPosition)
{
return groupPosition;
}
public override View GetGroupView(int groupPosition, bool isExpanded, View convertView, ViewGroup parent)
{
string headerTitle = (string)GetGroup(groupPosition);
convertView = convertView ?? _context.LayoutInflater.Inflate(Resource.Layout.HeaderCustomLayout, null);
var lblListHeader = (TextView)convertView.FindViewById(Resource.Id.lblListHeader);
lblListHeader.Text = headerTitle;
return convertView;
}
public override bool HasStableIds
{
get
{
return false;
}
}
public override bool IsChildSelectable(int groupPosition, int childPosition)
{
return true;
}
class ViewHolderItem : Java.Lang.Object
{
}
}
}