1:activity代码

package com.example.android20_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;


public class MainActivity extends ExpandableListActivity {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// 一级条目
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<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<Map<String, String>> child2 = new ArrayList<Map<String, String>>();
Map<String, String> child2Data1 = new HashMap<String, String>();
child2Data1.put("child", "child2Data");
child2.add(child2Data1);

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);
}

}

layout文件夹下main.xml group.xml child.xml三个配置文件

main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

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


</LinearLayout>

group.xml 一级条目的控制显示格式的文件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

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

</LinearLayout>

child.xml 一级条目的控制显示格式的文件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<TextView
android:id="@+id/childTo"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingBottom="5px"
android:paddingLeft="50px"
android:paddingTop="5px"
android:text="No data"
android:textSize="20sp" />

</LinearLayout>

更多相关文章

  1. Android--一段兼容居中和满屏满屏的布局
  2. 简单创建Android(安卓)MVVM模式代码
  3. Android(安卓)Canvas练习(7)绘制欧冠八强防守&控制率数据对比图
  4. android studio项目的导出和导入
  5. XBMC Romote:用 Android(安卓)手机控制 XBMC 媒体播放
  6. [Java][Android][Process] Process 创建+控制+分析 经验浅谈
  7. android远程控制(一)---从PC端写数据到android系统驱动让android系
  8. Android(安卓)OpenGLES2.0(十四)——Obj格式3D模型加载
  9. Android实现电量控制降低耗电

随机推荐

  1. 手动安装配置Android(安卓)Studio
  2. android 启动过程及init.rc
  3. 【Android】Error[*,*]Could not find met
  4. iOS Airplay--Airtunes音乐播放在Android
  5. android sdk配置
  6. Android(安卓)页面自动切换实现
  7. android 驱动(6)---DTS 分析
  8. Android 布局属性 Android:layout_weight
  9. android平台下UITesting环境配置
  10. 谷歌宣布Android Studio将取代Eclipse