android-ExpandableListView(2)
2011-08-04 13:55
232 查看
package zhang.example; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import android.os.Bundle; import android.view.View; import android.widget.ExpandableListView; import android.widget.SimpleExpandableListAdapter; import android.widget.Toast; public class ExpandableListActivity extends android.app.ExpandableListActivity { /** Called when the activity is first created. */ @SuppressWarnings("unchecked") @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); List topList = new ArrayList(); Map topMap1 =new HashMap(); Map topMap2 =new HashMap(); Map topMap3 = new HashMap(); Map topMap4 = new HashMap(); topMap1.put("month", "1月测评项"); topMap2.put("month", "2月测评项"); topMap3.put("month" ,"3月测试项"); topMap4.put("month" ,"4月测试项"); topList.add(topMap1); topList.add(topMap2); topList.add(topMap3); topList.add(topMap4); List nestList = new ArrayList(); List nestList1 = new ArrayList(); Map nestMap1 = new HashMap(); Map nestMap2 = new HashMap(); Map nestMap3 = new HashMap(); nestMap1.put("test", "look"); nestMap2.put("test", "leat"); nestMap3.put("test", "play"); nestList1.add(nestMap1); nestList1.add(nestMap2); nestList1.add(nestMap3); List nestList2= new ArrayList(); Map nestMap4 = new HashMap(); Map nestMap5 = new HashMap(); nestMap4.put("test", "trun"); nestMap5.put("test", "direction"); nestList2.add(nestMap4); nestList2.add(nestMap5); List nestList3= new ArrayList(); Map nestMap6 = new HashMap(); Map nestMap7 =new HashMap(); Map nestMap8 = new HashMap(); nestMap6.put("test", "aaa"); nestMap7.put("test", "bbb"); nestMap8.put("test", "ccc"); nestList3.add(nestMap6); nestList3.add(nestMap7); nestList3.add(nestMap8); List nestList4 =new ArrayList(); Map nestMap9 = new HashMap(); Map nestMap10 = new HashMap(); nestMap9.put("test", "111"); nestMap10.put("test","222"); nestList4.add(nestMap9); nestList4.add(nestMap10); nestList.add(nestList1); nestList.add(nestList2); nestList.add(nestList3); nestList.add(nestList4); SimpleExpandableListAdapter adapter = new SimpleExpandableListAdapter( this,//1 topList, //2顶层数据列表 android.R.layout.simple_dropdown_item_1line, //3一层显示样式 new String[]{"month"}, //4顶层Map new int[]{android.R.id.text1}, //5顶层数据显示的View nestList, //6二层数据列表 android.R.layout.simple_list_item_1, //7二层显示的样式 new String[]{"test"}, //8二层map new int[]{android.R.id.text1}//9二层数据的View ); this.setListAdapter(adapter); } public boolean onClickClick(ExpandableListView parent,View v,int groupPosition,int ChildPosition ,long id){ Toast.makeText(this, "嵌套列表被点击,顶层列表定位"+groupPosition+"二层列表定位"+ChildPosition,Toast.LENGTH_LONG).show(); return super.onChildClick(parent, v, groupPosition, ChildPosition, id); } @Override public void onGroupCollapse(int groupPosition) { Toast.makeText(this, "顶层列表收缩,列表定位"+groupPosition, Toast.LENGTH_LONG).show(); super.onGroupCollapse(groupPosition); } @Override public void onGroupExpand(int groupPosition) { // TODO Auto-generated method stub Toast.makeText(this, "顶层列表展开,列表定位"+groupPosition, Toast.LENGTH_LONG).show(); super.onGroupExpand(groupPosition); } }
<?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:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@id/android:list"> </ExpandableListView> </LinearLayout>
相关文章推荐
- android ExpandableListView position - packPostion - group/childposition
- Android之实现QQ好友分组(ExpandableListView)
- android 二级列表 expandablelistview 下标越界的解决
- Android中ExpandableListView的使用 (二)
- android ExpandableListView setOnChildClickListener事件失效问题
- Android改变ExpandableListView的indicator图标实现方法
- android 实现QQ好友列表(扩展listview:ExpandableListView)
- Android ExpandableListView 带有Checkbox的简单应用
- Android 自定义下拉刷新ExpandableListView
- Android之ExpandableListView的各种效果(默认展开不合闭,自定义父栏目及箭头控制)
- Android ExpandableListView 中完美嵌套 GridView
- Android中ExpandableListView的使用
- Android ExpandableListView 中完美嵌套 GridView
- Android ExpandableListView嵌套ListView
- android控件-ExpandableListView
- Android之ExpandableListView的属性(Group不展开)
- android-ExpandableListView的使用
- Android:ExpandableListView使用
- Android之ExpandableListView的属性(Group不展开)
- Android UI开发第二篇——多级列表(ExpandableListView)