expandList.setAdapter(sela);
就可以了。 当然, 响应事件Listener也可以自己添加。
附:另一个例子
ExpandableListView的用法与ListView和GridView,Gallery 类似,都是通过一个Adapter来显示.
main.xml:
<LinearLayout xmlns:android="http://www.easck.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ExpandableListView android:id="@+id/elv" android:indicatorRight="160dp"
android:layout_width="fill_parent" android:layout_height="fill_parent">
</ExpandableListView>
<!-- indicatorRight 设置那个小图标右边缘与 ExpandableListView左边缘的间距-->
</LinearLayout>
ElvAdapter.java
复制代码 package com.test;
import java.util.ArrayList;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.TextView;
import android.widget.LinearLayout.LayoutParams;
public class ElvAdapter extends BaseExpandableListAdapter
{
ArrayList<ElvObject> objs;
Context context;
ElvAdapter(Context context,ArrayList<ElvObject> objs)
{
this.objs=objs;
this.context=context;
}
@Override
public Object getChild(int groupPosition, int childPosition)
{
// TODO Auto-generated method stub
return objs.get(groupPosition).childs.get(childPosition);
}
@Override
public long getChildId(int groupPosition, int childPosition)
{
// TODO Auto-generated method stub
return childPosition;
}
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent)










