打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Android中ExpandableListView的使用
  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. }  
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Android版手风琴(ExpandableListView)
ExpandableListView方法详解
关于ExpandableListView用法的一个简单小例子
Android开发资料
Android 高仿QQ 好友分组列表
ExpandableListView(三)只展开一个group,没有child不展开group
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服