android-ExpandableListView(2)

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>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值