ExpandableList可展开的list

老规矩。右键取得显示不出来的图片地址,利用下载工具下载这个图片。后缀改为rar即可得到源代码项目。
 
 
package zhang.EspandableListView;import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;import android.app.ExpandableListActivity;
import android.os.Bundle;
import android.widget.SimpleExpandableListAdapter;public class Espandable extends ExpandableListActivity {	/** Called when the activity is first created. */@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);// 定义一个list。该list对象为一级条目提供数据List<Map<String,String>> groups = new ArrayList<Map<String,String>>();Map<String,String> group1= new HashMap<String,String>();group1.put("group", "group1");groups.add(group1);Map<String,String> group2= new HashMap<String,String>();group2.put("group", "group2");groups.add(group2);//定义一个list 该list·对象为第一个一级条目提供二级条目的数据List<Map<String,String>> child1=new ArrayList<Map<String,String>>();Map<String,String> childDate11= new HashMap<String,String>();childDate11.put("child", "childDate11");child1.add(childDate11);Map<String,String> childDate12= new HashMap<String,String>();childDate12.put("child", "childDate12");child1.add(childDate12);//定义一个list 该list·对象为第二个一级条目提供二级条目的数据List<Map<String,String>> child2 =new ArrayList<Map<String,String>>();Map<String,String> childDate21 =new HashMap<String,String>();childDate21.put("child", "childDare21");child2.add(childDate21);Map<String,String> childDate22= new HashMap<String,String>();childDate22.put("child", "childDate22");child2.add(childDate22);// 定义一个list该list对象用来存储所有的二级条目的数据List<List<Map<String,String>>> childs = new ArrayList<List<Map<String,String>>>();childs.add(child1);childs.add(child2);//1生成一个simpleExpandableListAdapter//2context//3 一级条目的样式布局文件//4·指定一级条目数据的key//5指定一句条目数据显示控件的ID//6指定二级条目的数据//7指定二级条目的布局文件//8指定二级条目数据的key//9指定二级条目数据显示控件的IDSimpleExpandableListAdapter sela=  new SimpleExpandableListAdapter(this,groups,R.layout.gruop,new String[]{"group"},new int[]{R.id.gruopTo},childs,R.layout.child,new String[]{"child"},new int []{R.id.childTo});setListAdapter(sela);}
} 
主页布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent"><ExpandableListView android:id="@id/android:list" android:layout_height="fill_parent" android:layout_width="fill_parent"android:drawSelectorOnTop="false"></ExpandableListView>
<TextView  android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="No Date"/>
</LinearLayout>
 
一级list的布局 gruop。xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent"><TextView  android:id="@+id/gruopTo"android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="No Data"android:paddingLeft="60px"android:paddingTop="10px"android:textSize="26sp"/>
</LinearLayout>
 
子布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent"><TextView  android:id="@+id/childTo"android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="No Data"android:paddingLeft="30px"android:paddingTop="5px"android:textSize="16sp"/>
</LinearLayout>
 












