android------列中列的列表ExpandableListActivity对象

1、main.xml代码:
<RelativeLayout 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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".Activity01" >

	<ExpandableListView 
	    android:id="@id/android:list"
	    android:layout_width="fill_parent"
	    android:layout_height="wrap_content"
	    android:drawSelectorOnTop="false"/>
	    <TextView
	        android:id="@id/android:empty"
      		android:layout_width="fill_parent"
       		android:layout_height="wrap_content"
       		android:text="NO data!"/>
	    <!-- android:drawSelectorOnTop="false"  是选项高亮部分不覆盖文字 -->
</RelativeLayout>

2、group.xml代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
   
<TextView 
        android:id="@+id/groupto"
		android:layout_width="fill_parent"
    	android:layout_height="fill_parent"
    	android:paddingLeft="60px"
    	android:textSize="26sp"
    	android:text="NO DATA!"/>
</LinearLayout>

3、child.xml代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    
 	<TextView 
        android:id="@+id/childto"
		android:layout_width="fill_parent"
    	android:layout_height="fill_parent"
    	android:paddingLeft="60px"
    	android:textSize="20sp"
    	android:text="NO DATA!"/>
</LinearLayout>

4、Activity01.java代码:
package mars.expandablelistactivity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.os.Bundle;
import android.widget.SimpleExpandableListAdapter;
import android.app.ExpandableListActivity;

public class Activity01 extends ExpandableListActivity {

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		
		//定义一个List,为一级条目提供数据
		List<Map<String,String>> groups=new ArrayList<Map<String,String>>();
		Map<String,String> group1=new HashMap<String,String>();
		group1.put("group", "group1");
		Map<String,String> group2=new HashMap<String,String>();
		group2.put("group", "group2");
		groups.add(group1);
		groups.add(group2);
		
		//定义一个List,为第一个条目增加二级条目的数据
		List<Map<String,String>> child1=new ArrayList<Map<String,String>>();
		Map<String,String> childDate1=new HashMap<String,String>();
		childDate1.put("child", "childDate1");
		Map<String,String> childDate2=new HashMap<String,String>();
		childDate2.put("child", "childDate2");
		child1.add(childDate1);
		child1.add(childDate2);
		
		//定义一个List,为第二个条目增加二级条目的数据
		List<Map<String,String>> child2=new ArrayList<Map<String,String>>();
		Map<String,String> childDate3=new HashMap<String,String>();
		childDate3.put("child", "childDate1");
		child2.add(childDate3);
		
		//定义一个List,存储所有二级条目的数据
		List<List<Map<String,String>>> childs=new  ArrayList<List<Map<String,String>>>();
		childs.add(child1);
		childs.add(child2);
		
		SimpleExpandableListAdapter sela=new SimpleExpandableListAdapter(
				this,
				groups,
				R.layout.group,
				new String[]{"group"},
				new int[]{R.id.groupto},
				childs,
				R.layout.child,
				new String[]{"child"},
				new int[]{R.id.childto}
				);
		setListAdapter(sela);
	}
}
5、运行效果:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值