Advertisement
Guest User

Untitled

a guest
Mar 17th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.40 KB | None | 0 0
  1. public class ExpandableListAdapter extends BaseExpandableListAdapter {
  2.  
  3. private Context _context;
  4. private List<String> _listDataHeader ;
  5. private HashMap<String, List<String>> _listDataChild;
  6.  
  7. public ExpandableListAdapter(Context context, List<String> listDataHeader,
  8. HashMap<String, List<String>> listChildData) {
  9. this._context = context;
  10. this._listDataHeader = listDataHeader;
  11. this._listDataChild = listChildData;
  12. }
  13.  
  14. @Override
  15. public Object getChild(int groupPosition, int childPosititon) {
  16. return this._listDataChild.get(this._listDataHeader.get(groupPosition))
  17. .get(childPosititon);
  18. }
  19.  
  20. @Override
  21. public long getChildId(int groupPosition, int childPosition) {
  22. return childPosition;
  23. }
  24.  
  25. @Override
  26. public View getChildView(int groupPosition, final int childPosition,
  27. boolean isLastChild, View convertView, ViewGroup parent) {
  28.  
  29. final String childText = (String) getChild(groupPosition, childPosition);
  30.  
  31. if (convertView == null) {
  32. LayoutInflater infalInflater = (LayoutInflater) this._context
  33. .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  34. convertView = infalInflater.inflate(R.layout.list_item, null);
  35. }
  36.  
  37. TextView txtListChild = (TextView) convertView
  38. .findViewById(R.id.lblListItem);
  39.  
  40. txtListChild.setText(childText);
  41. return convertView;
  42. }
  43.  
  44. @Override
  45. public int getChildrenCount(int groupPosition) {
  46. return this._listDataChild.get(this._listDataHeader.get(groupPosition))
  47. .size();
  48. }
  49.  
  50. @Override
  51. public Object getGroup(int groupPosition) {
  52. return this._listDataHeader.get(groupPosition);
  53. }
  54.  
  55. @Override
  56. public int getGroupCount() {
  57. return this._listDataHeader.size();
  58. }
  59.  
  60. @Override
  61. public long getGroupId(int groupPosition) {
  62. return groupPosition;
  63. }
  64.  
  65. @Override
  66. public View getGroupView(int groupPosition, boolean isExpanded,
  67. View convertView, ViewGroup parent) {
  68. String headerTitle = (String) getGroup(groupPosition);
  69. if (convertView == null) {
  70. LayoutInflater infalInflater = (LayoutInflater) this._context
  71. .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  72. convertView = infalInflater.inflate(R.layout.list_group, null);
  73. }
  74.  
  75. TextView lblListHeader = (TextView) convertView
  76. .findViewById(R.id.lblListHeader);
  77. lblListHeader.setTypeface(null, Typeface.BOLD);
  78. lblListHeader.setText(headerTitle);
  79.  
  80. return convertView;
  81. }
  82.  
  83. @Override
  84. public boolean hasStableIds() {
  85. return false;
  86. }
  87.  
  88. @Override
  89. public boolean isChildSelectable(int groupPosition, int childPosition) {
  90. return true;
  91. }
  92. }
  93.  
  94. public class MainActivityFragment extends Fragment {
  95.  
  96. //Expandable list Adapter
  97. ExpandableListAdapter listAdapter;
  98. ExpandableListView expListView;
  99. List<String> listDataHeader;
  100. HashMap<String, List<String>> listDataChild;
  101.  
  102. //Users
  103. private List <User> items = new ArrayList<>();
  104.  
  105. //Obejeto a pasar
  106. User user = new User();
  107. String password;
  108.  
  109. @Override
  110. public View onCreateView(LayoutInflater inflater, final ViewGroup container,
  111. Bundle savedInstanceState) {
  112. view = inflater.inflate(R.layout.fragment_main, container, false);
  113.  
  114. //Botones
  115. TextPass = (EditText) view.findViewById(R.id.IdpasswordUser);
  116. TextName = (TextView) view.findViewById(R.id.text1);
  117.  
  118. // get the listview
  119. expListView = (ExpandableListView) view.findViewById(R.id.lvExp);
  120.  
  121. // preparing list data
  122. prepareListData();
  123.  
  124. listAdapter = new ExpandableListAdapter(getActivity(), listDataHeader, listDataChild);
  125.  
  126. // setting list adapter
  127. expListView.setAdapter(listAdapter);
  128.  
  129. ExpandableListView ExList =(ExpandableListView) view.findViewById(R.id.lvExp) ;
  130.  
  131.  
  132.  
  133. //Llamamos al boton fichar
  134. fichar = (Button) view.findViewById(R.id.fichar);
  135.  
  136. //Call ExpandibleList view child on pressed
  137.  
  138. ExList.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
  139.  
  140. @Override
  141. public boolean onChildClick(ExpandableListView parent, View v,
  142. int groupPosition, int childPosition, long id) {
  143.  
  144. ShowItem(listDataHeader.get(childPosition));
  145.  
  146. TextName.setText(listAdapter.getChild(groupPosition,childPosition).toString());
  147.  
  148. return false;
  149. }
  150. });
  151.  
  152. fichar.setOnClickListener(new View.OnClickListener() {
  153. @Override
  154. public void onClick(View v) {
  155. password = TextPass.getText().toString();
  156. //SuperUsuario
  157. if(key.equalsIgnoreCase("cesi.tic")&&password.equalsIgnoreCase("123456789")){
  158. ((MainActivity) getActivity()).EditarUsuario();
  159. fichar.setVisibility(view.INVISIBLE);
  160. TextPass.setVisibility(view.INVISIBLE);
  161. TextDNI.setVisibility(view.INVISIBLE);
  162. }else{
  163. LeerFirebase();
  164. }
  165.  
  166. }
  167. });
  168. return view;
  169. }
  170. public void ShowItem(String id)
  171. {
  172. // do something
  173. }
  174. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement