Android28_ExpandableListActivity

 

ExpandableListActivity就是可扩展的list,单击某个item后,又可显示一个子list。它的数据通过绑定到ExpandableListAdapter或者ExpandableListAdapter的子类上。

       1.在主(main.xml)布局文件中声明ExpandableListActivity控件:

 

<ExpandableListView android:id="@id/android:list" 
    	android:layout_width="fill_parent"
    	android:layout_height="fill_parent"/>

        2.在组(group.xml)布局文件中声明group样式:

 

<TextView android:id="@+id/group" 
		android:layout_width="fill_parent"
		android:layout_height="fill_parent" 
		android:paddingLeft="60px" 
		android:paddingTop="10px"
		android:paddingBottom="10px" 
		android:textSize="26sp" />

        3.在子(child.xml)布局文件中声明子条目的样式:

 

<TextView android:id="@+id/subitem" 
		android:layout_width="fill_parent"
		android:layout_height="fill_parent" 
		android:paddingLeft="60px" 
		android:paddingTop="10px"
		android:paddingBottom="10px" 
		android:textSize="20sp" />

        4.创建Activity,并继承ExpandableListActivity

 

public class ExpandableListViewActivity extends ExpandableListActivity{}

5.group创建数据:

 

//定义group的list
List<Map<String,String>> groups = new ArrayList<Map<String,String>>();
Map<String,String> group1 = new HashMap<String,String>();
group1.put("group", "第一组");
Map<String,String> group2 = new HashMap<String,String>();
group2.put("group", "第二组");
groups.add(group1);
groups.add(group2);

        6.child创建数据:

 

        //定义group下的子条目
        List<Map<String,String>> subItem1 = new ArrayList<Map<String,String>>();
        Map<String,String> item11 = new HashMap<String, String>();
        item11.put("item", "第一条");
        Map<String,String> item12 = new HashMap<String,String>();
        item12.put("item", "第二条");
        subItem1.add(item11);
        subItem1.add(item12);
        
        List<Map<String,String>> subItem2 = new ArrayList<Map<String,String>>();
        Map<String,String> item21 = new HashMap<String, String>();
        item21.put("item", "第一条");
        Map<String,String> item22 = new HashMap<String,String>();
        item22.put("item", "第二条");
        Map<String,String> item23 = new HashMap<String,String>();
        item23.put("item", "第三条");
        subItem2.add(item21);
        subItem2.add(item22);
        subItem2.add(item23);
        
        List<List<Map<String,String>>> subItems = new ArrayList<List<Map<String,String>>>();
        subItems.add(subItem1);
        subItems.add(subItem2);

 创建SimpleExpandableListAdapter的步骤

 

	SimpleExpandableListAdapter s = new SimpleExpandableListAdapter(
        		this, groups, R.layout.group, new String[]{"group"}, 
        		new int[]{R.id.group},subItems, R.layout.subitem, 
			new String[]{"item"}, new int[]{R.id.subitem});
    	setListAdapter(s);

 Adapter构造方法共有9个参数,分别为:(1Context.2)一级条目的数据(3)一级条目的布局(4)一级条目的key5)一级条目的数据显示控件的id6)二级条目的数据(7)二级条目的布局(8)二级条目数据的key9)二级条目数据控件的id

运行结果:



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断路器保护灵敏度校验整改及剩余电流监测试点应用站用交流系统断

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值