Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.18 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:orientation="vertical"
  4. android:layout_width="fill_parent"
  5. android:layout_height="wrap_content">
  6. <TextView
  7. android:id="@+id/adapter_expandable_listview_header_textview"
  8. android:layout_width="match_parent"
  9. android:text="Header"
  10. android:textStyle="bold"
  11. android:textSize="14sp"
  12. android:textColor="@color/textColorSecondary"
  13. android:layout_height="wrap_content"
  14. android:layout_margin="16dp" />
  15. </LinearLayout>
  16.  
  17. <?xml version="1.0" encoding="utf-8"?>
  18. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  19. android:orientation="vertical"
  20. android:layout_width="match_parent"
  21. android:layout_height="wrap_content"
  22. android:minWidth="25px"
  23. android:minHeight="25px">
  24. <RelativeLayout
  25. android:layout_width="match_parent"
  26. android:layout_height="wrap_content"
  27. android:id="@+id/relativeLayout1"
  28. android:layout_marginLeft="16dp"
  29. android:layout_marginRight="16dp"
  30. android:layout_marginTop="16dp"
  31. android:layout_marginBottom="20dp"
  32. android:descendantFocusability="blocksDescendants">
  33. <TextView
  34. android:text="Rüttenscheider Stern"
  35. android:layout_width="wrap_content"
  36. android:layout_height="wrap_content"
  37. android:id="@+id/adapter_expandable_listview_listitem_textview1"
  38. android:textSize="16sp"
  39. android:textColor="@color/textColorPrimary" />
  40. <TextView
  41. android:text="Essen"
  42. android:layout_width="wrap_content"
  43. android:layout_height="wrap_content"
  44. android:layout_below="@id/adapter_expandable_listview_listitem_textview1"
  45. android:id="@+id/adapter_expandable_listview_listitem_textview2"
  46. android:textSize="14sp" />
  47. <TextView
  48. android:text="Rüttenscheiderstraße"
  49. android:layout_width="wrap_content"
  50. android:layout_height="wrap_content"
  51. android:layout_below="@id/adapter_expandable_listview_listitem_textview2"
  52. android:id="@+id/adapter_expandable_listview_listitem_textview3"
  53. android:textSize="14sp" />
  54. <ImageButton
  55. android:layout_width="wrap_content"
  56. android:layout_height="wrap_content"
  57. android:layout_alignParentRight="true"
  58. android:layout_alignParentTop="true"
  59. android:id="@+id/adapter_expandable_listview_listitem_overflow_button"
  60. android:src="@drawable/ic_dots_vertical_grey600_18dp"
  61. android:background="@null" />
  62. </RelativeLayout>
  63. <View
  64. android:layout_width="match_parent"
  65. android:layout_marginLeft="16dp"
  66. android:layout_height="1dp"
  67. android:background="@color/material_grey_300" />
  68. </LinearLayout>
  69.  
  70. namespace YourNamespace
  71. {
  72. /// <summary>
  73. /// Used to pass groups of objects to the adapter.
  74. /// </summary>
  75. internal class ExpandableItem
  76. {
  77. public string HeaderTitle;
  78. public List<FMNavigationListItem> ChildItems;
  79. }
  80.  
  81. /// <summary>
  82. /// Used internally by the adapter.
  83. /// </summary>
  84. internal class SectionedHeaderListItem
  85. {
  86. public string HeaderTitle;
  87. public FMNavigationListItem Item;
  88.  
  89. public SectionedHeaderListItem(string headerTitle, FMNavigationListItem item)
  90. {
  91. HeaderTitle = headerTitle;
  92. Item = item;
  93. }
  94. }
  95.  
  96. /// <summary>
  97. ///
  98. /// </summary>
  99. class SectionedHeaderListViewAdaper : BaseAdapter
  100. {
  101. const int TypeItem = 0;
  102. const int TypeSeperator = 1;
  103.  
  104. LayoutInflater mLayoutInflater;
  105. List<SectionedHeaderListItem> mDataItems;
  106. List<int> mSectionPositions;
  107.  
  108. /// <summary>
  109. ///
  110. /// </summary>
  111. /// <param name="context"></param>
  112. /// <param name="items"></param>
  113. public SectionedHeaderListViewAdaper(Context context, List<ExpandableItem> items)
  114. {
  115. mLayoutInflater = (LayoutInflater)context.GetSystemService(Context.LayoutInflaterService);
  116. mSectionPositions = new List<int>();
  117.  
  118. // Sort each item via header title.
  119. List<ExpandableItem> dataItems = items;
  120. dataItems.Sort(delegate (ExpandableItem e1, ExpandableItem e2)
  121. {
  122. return e1.HeaderTitle.CompareTo(e2.HeaderTitle);
  123. });
  124.  
  125. // Sort each child item alphabetically.
  126. foreach (var d in dataItems)
  127. {
  128. d.ChildItems.Sort(delegate (FMNavigationListItem i1, FMNavigationListItem i2)
  129. {
  130. return i1.DisplayAttributes[0].CompareTo(i2.DisplayAttributes[0]);
  131. });
  132. }
  133.  
  134. // Merge all items into one big list.
  135. mDataItems = new List<SectionedHeaderListItem>();
  136. int index = 0;
  137. foreach (var expandableItem in dataItems)
  138. {
  139. // Represents a section
  140. mDataItems.Add(new SectionedHeaderListItem(
  141. expandableItem.HeaderTitle,
  142. null));
  143. mSectionPositions.Add(index);
  144. index++;
  145.  
  146. // Now add the child items for the section
  147. foreach (var dataItem in expandableItem.ChildItems)
  148. {
  149. mDataItems.Add(new SectionedHeaderListItem(
  150. expandableItem.HeaderTitle,
  151. dataItem));
  152. index++;
  153. }
  154. }
  155. }
  156.  
  157. public override Java.Lang.Object GetItem(int position)
  158. {
  159. return position;
  160. }
  161.  
  162. public override long GetItemId(int position)
  163. {
  164. return position;
  165. }
  166.  
  167. public FMNavigationListItem ItemAt(int position)
  168. {
  169. return mDataItems[position].Item;
  170. }
  171.  
  172. /// <summary>
  173. /// One view for the header and another for
  174. /// the normal cells.
  175. /// </summary>
  176. public override int ViewTypeCount
  177. {
  178. get
  179. {
  180. return 2;
  181. }
  182. }
  183.  
  184. public override int GetItemViewType(int position)
  185. {
  186. if (mSectionPositions.Contains(position))
  187. return TypeSeperator;
  188. return TypeItem;
  189. }
  190.  
  191. public override int Count
  192. {
  193. get
  194. {
  195. return mDataItems.Count;
  196. }
  197. }
  198.  
  199. public override View GetView(int position, View convertView, ViewGroup parent)
  200. {
  201. SectionedHeaderListViewAdaperViewHolder holder = null;
  202. int rowType = GetItemViewType(position);
  203.  
  204. // Inflate the correct layout
  205. if (convertView == null)
  206. {
  207. holder = new SectionedHeaderListViewAdaperViewHolder();
  208. switch(rowType)
  209. {
  210. case TypeItem:
  211. convertView = mLayoutInflater.Inflate(
  212. Resource.Layout.adapter_expandable_listview_listitem,
  213. null);
  214. break;
  215. case TypeSeperator:
  216. convertView = mLayoutInflater.Inflate(
  217. Resource.Layout.adapter_expandable_listview_header,
  218. null);
  219. break;
  220. }
  221. convertView.Tag = (SectionedHeaderListViewAdaperViewHolder)convertView.Tag;
  222. }
  223. else
  224. {
  225. holder = (SectionedHeaderListViewAdaperViewHolder)convertView.Tag;
  226. }
  227.  
  228. //Populate UI components
  229. SectionedHeaderListItem item = mDataItems[position];
  230. switch (rowType)
  231. {
  232. case TypeItem:
  233. // Horrible code incomming
  234. holder.DispAttsTextViews = new List<TextView>();
  235. holder.DispAttsTextViews.Add(convertView.FindViewById<TextView>(Resource.Id.adapter_expandable_listview_listitem_textview1));
  236. holder.DispAttsTextViews.Add(convertView.FindViewById<TextView>(Resource.Id.adapter_expandable_listview_listitem_textview2));
  237. holder.DispAttsTextViews.Add(convertView.FindViewById<TextView>(Resource.Id.adapter_expandable_listview_listitem_textview3));
  238. holder.DispAttsTextViews[0].Text = item.Item.DisplayAttributes[0];
  239. holder.DispAttsTextViews[1].Text = item.Item.DisplayAttributes[1];
  240. holder.DispAttsTextViews[2].Text = item.Item.DisplayAttributes[2];
  241. break;
  242. case TypeSeperator:
  243. holder.HeaderTextView = convertView.FindViewById<TextView>(Resource.Id.adapter_expandable_listview_header_textview);
  244. holder.HeaderTextView.Text = item.HeaderTitle;
  245. break;
  246. }
  247. return convertView;
  248. }
  249. }
  250.  
  251. class SectionedHeaderListViewAdaperViewHolder : Java.Lang.Object
  252. {
  253. public TextView HeaderTextView { get; set; }
  254. public List<TextView> DispAttsTextViews { get; set; }
  255. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement