<?xmlversion="1.0"encoding="utf-8"?>
<LinearLayoutxmlns: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_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false"
></ExpandableListView>
<TextView
android:id="@id/android:empty"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/nodata"
/>
</LinearLayout>
<?xmlversion="1.0"encoding="utf-8"?>
<LinearLayoutxmlns: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/gender"
android:layout_width="180dp"
android:layout_height="40dp"
android:textSize="10pt"
android:textColor="#fff"
android:layout_marginLeft="40dp"
android:paddingTop="5dp"
android:text="@string/nodata"
/>
</LinearLayout>
<?xmlversion="1.0"encoding="utf-8"?>
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/name"android:layout_width="180dp"android:layout_height="40dp"android:layout_marginLeft="20dp"android:paddingTop="10dp"android:textColor="#fff"android:text="@string/nodata"
/>
<TextView
android:id="@+id/age"android:layout_width="180dp"android:layout_height="40dp"android:layout_marginLeft="20dp"android:paddingTop="10dp"android:textColor="#fff"android:text="@string/nodata"
/>
</LinearLayout>
publicclass SimpleExpandableListAdapterDemoActivity extends
ExpandableListActivity {
private List<List<HashMap<String,String>>> childs = null;
private List<HashMap<String,String>> gender = null;
@Override
protectedvoid onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.expandable);
gender = new ArrayList<HashMap<String,String>>();
HashMap<String,String> male = new HashMap<String, String>();
male.put("gender", "Male");
HashMap<String,String> female = new HashMap<String, String>();
female.put("gender", "Female");
gender.add(male);
gender.add(female);
List<HashMap<String,String>> men = new ArrayList<HashMap<String,String>>();
HashMap<String,String> man1 = new HashMap<String, String>();
man1.put("name", "Theron");
man1.put("age", "25");
HashMap<String,String> man2 = new HashMap<String, String>();
man2.put("name", "Jack");
man2.put("age", "62");
men.add(man1);
men.add(man2);
List<HashMap<String,String>> women = new ArrayList<HashMap<String,String>>();
HashMap<String,String> woman1 = new HashMap<String, String>();
woman1.put("name", "Helen");
woman1.put("age", "12");
HashMap<String,String> woman2 = new HashMap<String, String>();
woman2.put("name", "Alice");
woman2.put("age", "15");
women.add(woman1);
women.add(woman2);
childs = new ArrayList<List<HashMap<String,String>>>();
childs.add(men);
childs.add(women);
SimpleExpandableListAdapter adapter = new SimpleExpandableListAdapter(SimpleExpandableListAdapterDemoActivity.this, gender, R.layout.expandable, R.layout.group, new String[]{
"gender"}, newint[]{R.id.gender}, childs, R.layout.child, new String[]{ "name","age"}, newint[]{R.id.name,R.id.age});setListAdapter(adapter);
}
@Override
publicboolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
// TODO Auto-generated method stub
Toast.makeText(SimpleExpandableListAdapterDemoActivity.this, childs.get(groupPosition).get(childPosition).get("name")+" is a "+gender.get(groupPosition).get("gender"), Toast.LENGTH_SHORT).show();
returntrue;
}
}