Guest User

Untitled

a guest
Sep 12th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.41 KB | None | 0 0
  1. package world.andriel.common.client_b.choosedistrostation.view;
  2.  
  3.  
  4. import java.util.HashMap;
  5. import java.util.List;
  6. import android.content.Context;
  7. import android.graphics.Typeface;
  8. import android.view.LayoutInflater;
  9. import android.view.View;
  10. import android.view.ViewGroup;
  11. import android.widget.BaseExpandableListAdapter;
  12. import android.widget.TextView;
  13.  
  14. import world.andriel.common.R;
  15.  
  16. public class CustomExpandableListAdapter extends BaseExpandableListAdapter {
  17.  
  18. private Context context;
  19. private List<String> expandableListTitle;
  20. private HashMap<String, List<String>> expandableListDetail;
  21.  
  22. public CustomExpandableListAdapter(Context context, List<String> expandableListTitle,
  23. HashMap<String, List<String>> expandableListDetail) {
  24. this.context = context;
  25. this.expandableListTitle = expandableListTitle;
  26. this.expandableListDetail = expandableListDetail;
  27. }
  28.  
  29. @Override
  30. public Object getChild(int listPosition, int expandedListPosition) {
  31. return this.expandableListDetail.get(this.expandableListTitle.get(listPosition))
  32. .get(expandedListPosition);
  33. }
  34.  
  35. @Override
  36. public long getChildId(int listPosition, int expandedListPosition) {
  37. return expandedListPosition;
  38. }
  39.  
  40. @Override
  41. public View getChildView(int listPosition, final int expandedListPosition,
  42. boolean isLastChild, View convertView, ViewGroup parent) {
  43. final String expandedListText = (String) getChild(listPosition, expandedListPosition);
  44. if (convertView == null) {
  45. LayoutInflater layoutInflater = (LayoutInflater) this.context
  46. .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  47. convertView = layoutInflater.inflate(R.layout.list_item, null);
  48. }
  49. TextView expandedListTextView = (TextView) convertView
  50. .findViewById(R.id.expandedListItem);
  51. expandedListTextView.setText(expandedListText);
  52. return convertView;
  53. }
  54.  
  55. @Override
  56. public int getChildrenCount(int listPosition) {
  57. return this.expandableListDetail.get(this.expandableListTitle.get(listPosition))
  58. .size();
  59. }
  60.  
  61. @Override
  62. public Object getGroup(int listPosition) {
  63. return this.expandableListTitle.get(listPosition);
  64. }
  65.  
  66. @Override
  67. public int getGroupCount() {
  68. return this.expandableListTitle.size();
  69. }
  70.  
  71. @Override
  72. public long getGroupId(int listPosition) {
  73. return listPosition;
  74. }
  75.  
  76. @Override
  77. public View getGroupView(int listPosition, boolean isExpanded,
  78. View convertView, ViewGroup parent) {
  79. String listTitle = (String) getGroup(listPosition);
  80. if (convertView == null) {
  81. LayoutInflater layoutInflater = (LayoutInflater) this.context.
  82. getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  83. convertView = layoutInflater.inflate(R.layout.list_group, null);
  84. }
  85. TextView listTitleTextView = (TextView) convertView
  86. .findViewById(R.id.listTitle);
  87. listTitleTextView.setTypeface(null, Typeface.BOLD);
  88. listTitleTextView.setText(listTitle);
  89. return convertView;
  90. }
  91.  
  92. @Override
  93. public boolean hasStableIds() {
  94. return false;
  95. }
  96.  
  97. @Override
  98. public boolean isChildSelectable(int listPosition, int expandedListPosition) {
  99. return true;
  100. }
  101. }
Add Comment
Please, Sign In to add comment