This example is very simple, simple to a beginner can be casually developed, today's purpose is only to achieve the effect, if you want to go deep here are a few very good blog:
several special properties of Android Expandablelistview
http://blog.csdn.net/t12x3456/article/details/7828620
Expandablelistview explanation
Http://www.apkbus.com/thread-124715-1-1.html
As with the ListView, we need to inherit an adapter called Baseexpandlistadapter, and then rewrite the methods of several parent classes.
Package com.example.uitest;
Import Android.content.Context;
Import Android.view.LayoutInflater;
Import Android.view.View;
Import Android.view.ViewGroup;
Import Android.widget.BaseExpandableListAdapter;
public class Treeadapter extends baseexpandablelistadapter{
Context context;
Public Treeadapter (Context context) {
Super ();
This.context = context;
}
@Override
Public Object getchild (int arg0, int arg1) {
return 0;
}
@Override
public long Getchildid (int arg0, int arg1) {
TODO auto-generated Method Stub
return 0;
}
@Override
Public View getchildview (int arg0, int arg1, Boolean arg2, view V,
ViewGroup Arg4) {
v = layoutinflater.from (context). Inflate (r.layout.item2, NULL);
return v;
}
@Override
public int Getchildrencount (int arg0) {
TODO auto-generated Method Stub
return 3;
}
@Override
Public Object getgroup (int arg0) {
TODO auto-generated Method Stub
return null;
}
@Override
public int GetGroupCount () {
return 3;
}
@Override
public long getgroupid (int arg0) {
return 0;
}
@Override
Public View getgroupview (int arg0, Boolean arg1, View V, ViewGroup VGs) {
v = layoutinflater.from (context). Inflate (r.layout.item_autocomplete, NULL);
return v;
}
@Override
public Boolean hasstableids () {
TODO auto-generated Method Stub
return false;
}
@Override
public boolean ischildselectable (int arg0, int arg1) {
TODO auto-generated Method Stub
return false;
}
}
Here we only operate four functions, namely:
public int Getchildrencount (int arg0);//Gets the sub-layout total record of the level two list, which is the number of rows
public int getgroupcount ();//Gets the number of rows for the first-level list
Public View getchildview (int arg0, int arg1, Boolean arg2, view V,
ViewGroup arg4);//Get the resource layout of level two list
Public View getgroupview (int arg0, Boolean arg1, View V, ViewGroup VGS);//Gets the number of rows for the first-level list
Finally, load the adapter into the Expandablelistview:
Expandablelistview view = (Expandablelistview) Findviewbyid (R.ID.ELV);
Treeadapter adapter = new Treeadapter (Getapplicationcontext ());
View.setadapter (adapter);
Main layout xml:
<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Xmlns:tools= "Http://schemas.android.com/tools"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent" >
<expandablelistview
Android:id= "@+id/elv"
Android:layout_width= "Fill_parent"
Android:groupindicator= "@null"
android:layout_height= "Wrap_content" ></ExpandableListView>
</LinearLayout>
This is the most condensed version of everyone should be able to understand quickly;
Android Development Tree Control Expandablelistview (i)