分享

Android中ExpandableListView的使用

 白玉老虎学堂 2014-05-13
  1. //ExpandableListView的Adapter   
  2. public  class  ExpandableAdapter extends  BaseExpandableListAdapter  
  3. {  
  4.     Activity activity;  
  5.       
  6.     public  ExpandableAdapter(Activity a)  
  7.     {  
  8.         activity = a;  
  9.     }  
  10.     public  Object getChild(int  groupPosition, int  childPosition)  
  11.     {  
  12.         return  childArray.get(groupPosition).get(childPosition);  
  13.     }  
  14.     public  long  getChildId(int  groupPosition, int  childPosition)  
  15.     {  
  16.         return  childPosition;  
  17.     }  
  18.     public  int  getChildrenCount(int  groupPosition)  
  19.     {  
  20.         return  childArray.get(groupPosition).size();  
  21.     }  
  22.     public  View getChildView(int  groupPosition, int  childPosition,  
  23.             boolean  isLastChild, View convertView, ViewGroup parent)  
  24.     {  
  25.         String string = childArray.get(groupPosition).get(childPosition);  
  26.         return  getGenericView(string);  
  27.     }  
  28.     // group method stub   
  29.     public  Object getGroup(int  groupPosition)  
  30.     {  
  31.         return  groupArray.get(groupPosition);  
  32.     }  
  33.     public  int  getGroupCount()  
  34.     {  
  35.         return  groupArray.size();  
  36.     }  
  37.     public  long  getGroupId(int  groupPosition)  
  38.     {  
  39.         return  groupPosition;  
  40.     }  
  41.     public  View getGroupView(int  groupPosition, boolean  isExpanded,  
  42.             View convertView, ViewGroup parent)  
  43.     {  
  44.         String string = groupArray.get(groupPosition);  
  45.         return  getGenericView(string);  
  46.     }  
  47.     // View stub to create Group/Children 's View   
  48.     public  TextView getGenericView(String string)  
  49.     {  
  50.         // Layout parameters for the ExpandableListView   
  51.         AbsListView.LayoutParams layoutParams = new  AbsListView.LayoutParams(  
  52.                 ViewGroup.LayoutParams.FILL_PARENT, 64 );  
  53.         TextView text = new  TextView(activity);  
  54.         text.setLayoutParams(layoutParams);  
  55.         // Center the text vertically   
  56.         text.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);  
  57.         // Set the text starting position   
  58.         text.setPadding(36000 );  
  59.         text.setText(string);  
  60.         return  text;  
  61.     }  
  62.     public  boolean  hasStableIds()  
  63.     {  
  64.         return  false ;  
  65.     }  
  66.     public  boolean  isChildSelectable(int  groupPosition, int  childPosition)  
  67.     {  
  68.         return  true ;  
  69.     }  
  70. }  

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约