ANDROID_MARS学习笔记_S02_004_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="com.example.s02_e03_expandablelistactivity.MainActivity" > <ExpandableListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@id/android:list"
android:background="#00FF00"
android:layout_weight="1"
android:drawSelectorOnTop="true"/>
<TextView
android:id="@id/android:empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FF0000"
android:text="No data"/> </RelativeLayout>
2.group.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="com.example.s02_e03_expandablelistactivity.MainActivity" > <TextView android:id="@+id/groupTo"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="60px"
android:paddingTop="10px"
android:paddingBottom="10px"
android:textSize="26sp"
android:background="#cccccc"
android:text="No group data" /> </RelativeLayout>
3.child.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="com.example.s02_e03_expandablelistactivity.MainActivity" > <TextView android:id="@+id/childTo"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="50px"
android:paddingTop="5px"
android:paddingBottom="5px"
android:textSize="20sp"
android:text="No child data" /> </RelativeLayout>
4.java
package com.example.s02_e03_expandablelistactivity; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map; import android.app.ExpandableListActivity;
import android.os.Bundle;
import android.widget.SimpleExpandableListAdapter; /*
* 创建一个Activity,继承ExpandableListAcitivty
*/
public class MainActivity extends ExpandableListActivity {
/** Called when the activity is first created. */
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); //定义一个List,该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对象为第一个一级条目提供二级条目的数据
List<Map<String,String>> child1 = new ArrayList<Map<String,String>>();
Map<String, String> child1Data1 = new HashMap<String, String>();
child1Data1.put("child", "child1Data1");
child1.add(child1Data1);
Map<String,String> child1Data2 = new HashMap<String,String>();
child1Data2.put("child", "child1Data2");
child1.add(child1Data2); //定义一个List,该List对象为第二个一级条目提供二级条目的数据
List<Map<String, String>> child2 = new ArrayList<Map<String, String>>();
Map<String, String> child2Data = new HashMap<String, String>();
child2Data.put("child", "child2Data");
child2.add(child2Data); //定义一个List,该List对象用来存储所有的二级条目的数据
List<List<Map<String, String>>> childs = new ArrayList<List<Map<String, String>>>();
childs.add(child1);
childs.add(child2); //生成一个SimpleExpandableListAdapter对象
//1.context
//2.一级条目的数据
//3.用来设置一级条目样式的布局文件
//4.指定一级条目数据的key
//5.指定一级条目数据显示控件的id
//6.指定二级条目的数据
//7.用来设置二级条目样式的布局文件
//8.指定二级条目数据的key
//9.指定二级条目数据显示控件的id
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});
//将SimpleExpandableListAdapter对象设置给当前的ExpandableListActivity
setListAdapter(sela);
} }
ANDROID_MARS学习笔记_S02_004_ExpandableListActivity的更多相关文章
- ANDROID_MARS学习笔记_S01_012_RatingBar
		1.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns: ... 
- ANDROID_MARS学习笔记_S01_012_SeekBar
		1.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns: ... 
- ANDROID_MARS学习笔记_S01_011ProgressBar
		文档是这样来设置样式 <ProgressBar android:layout_width="wrap_content" android:layout_height=" ... 
- ANDROID_MARS学习笔记_S01_010日期时间控件
		1.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns: ... 
- ANDROID_MARS学习笔记_S01_009Relative_LAYOUT例子
		1. <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android ... 
- ANDROID_MARS学习笔记_S01_008Linear_layout例子
		1.netstone_layout.xml <?xml version="1.0" encoding="utf-8"?> <LinearLay ... 
- ANDROID_MARS学习笔记_S01_007Linear_layout嵌套与layout_weight的设置
		一.介绍 二.1.linear_layout.xml <?xml version="1.0" encoding="utf-8"?> <Line ... 
- ANDROID_MARS学习笔记_S01_006ImageView
		一.ImageView介绍 设置scalType Must be one of the following constant values. Constant Value Description ma ... 
- ANDROID_MARS学习笔记_S01_005CheckBox
		一. 1.checkbox_layout.xml <?xml version="1.0" encoding="utf-8"?> <Linear ... 
随机推荐
- gwt-问题解决
			最近在看gwt,写了个demo,但是总是出问题,困扰了好几天,后台也没报错,但就是加载不出来 第一次编译以后是可以的,但是改了代码后就不行了,后台也没报错,google了好长时间也没出来. 于是换了个 ... 
- ###《Max-Margin Early Event Detectors》
			Paper reading. #@author: gr #@date: 2014-03-11 #@email: forgerui@gmail.com Early Detection Abstract: ... 
- Entity Framework 学习笔记(2)
			上期回顾:Entity Framework 学习笔记(1) Entity Framework最主要的东西,就是自己创建的.继承于DbContext的类: /// <summary> /// ... 
- aspx与mvc页面验证码
			验证码类代码 using System; using System.Collections.Generic; using System.Drawing; using System.Drawing.Dr ... 
- python BeautifulSoup find 方法
			这里我们重点讲一下find的几种用法,其他的类比: find(name=None, attrs={}, recursive=True, text=None, **kwargs) (ps:只讲几种用法, ... 
- Mac OSX 安装Python的paramiko模块经验总结
			一.简单介绍 最近需要用Python模拟登录远程服务器并自动执行一些代码,需要安装一个叫paramiko的模块. paramiko官方介绍遵循SSH2协议,支持以加密和认证的方式,进行远程服务器的连接 ... 
- Python的设计模式学习
			1.工厂模式 #encoding=utf-8 __author__ = 'kevinlu1010@qq.com' class ADD(): def getResult(self,*args): ret ... 
- 关于ASE日志空间示数不正常的解决办法
			最近某系统的ASE数据库出现了异常,经过各种努力,终于把数据库正常又起起来了.但是经过检查,发现在查看剩余日志空间的时候(sp_helpsegment 'logsegment'),发现显示出来 ... 
- 软件测试 -- 测试人员和QA的区别
			软件测试人员的职责是尽可能早的找出软件缺陷,确保得以修复. 而质量保证人员(QA)主要职责是创建或者制定标准和方法,提高促进软件开发能力和减少软件缺陷. 测试人员的主要工作是测试,质量保证人员日常工作 ... 
- 一步步学习ASP.NET MVC3 (1)——基础知识
			请注明转载地址:http://www.cnblogs.com/arhat 首先在这里我想声明一下,这个ASP.NET MVC3系列是我在授课过程中的一些经验,有什么不对的地方,请大家指出,我们共同的学 ... 
