LixtView的升级版,点击item选项有下拉列表的功能,展示出Listitem的List数据
1.先在xml设置三个布局。
ExpandableListView样式Layout,这个布局是总体布局,相当于activity布局,这里最好引用android自带id,因为java中最好是用ExpandableListActivity来实现这个功能。
<ExpandableListView android:id="@id/android:list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00FF00"
android:layout_weight="1"
android:drawSelectorOnTop="false"/>
一级条目样式groupLayout,这个布局是ListItem的布局,自己定义。
二级条目样式childLayout,这个布局是ListItem点击之后下拉别表里的item的布局。
2.创建两个数据源ArrayList<Hash<String,自己定义>>。
一个是给ExpandableListView提供数据,ExpandableListView有几个item就add几个Hash<String,自己定义>。
一个是给ExpandableListView里的item提供数据,点击item后的下拉列表有几个ChildItem就add几个HashMap<String,自己定义>。
至于HashMap<String,自己定义>里put几个数据,就要看,自己定义的布局样式了。
3.加载适配器。
我们选用的是继承ExpandableListActivity,这个类里有一些特殊的方法。我把Adapter里面的参数写得直白点了,应该能看懂吧。。。。。
SimpleExpandableListAdapter simpleExpandableListAdapter = new SimpleExpandableListAdapter(<span style="font-family: Arial, Helvetica, sans-serif;">context,</span>
<span style="font-family: Arial, Helvetica, sans-serif;">groupList,groupLayout,new String[]{"groupMapKey"},new int[]{groupWidgetId},</span>
<span style="font-family: Arial, Helvetica, sans-serif;">childList,childLayout,new String[]{"childMapKey"},new int[]{childWidgetId});</span>
这个完了之后,采用和ListAdapter相同的方法setListAdapter来加载适配器。就Ok了。