ExpandableListActivity
main.xml:
<?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:id="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false"/> <TextView android:id="@id/android:empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="No data"/>
</LinearLayout>
group.xml:
<?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"
> <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:text="No data" />
</LinearLayout>
child.xml:
<?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"> <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 data" />
</LinearLayout>
MainActivity.java:
package mars.expandable; 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
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.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);
}
}
效果如图:
ExpandableListActivity的更多相关文章
- 利用SimpleExpandableListAdapter为ExpandableListActivity提供数据
首先MainActivity继承自ExpandableListActivity,其中的声明如下: setContentView(R.layout.expandmain); //定义一个:List,该L ...
- 仿qq联系人 学习笔记---ExpandableListActivity的使用
[转]原地址 http://blog.163.com/xygzx@126/blog/static/237809502011102010100331/ 效果显示图: 1.布局文件 main.xml(E ...
- android之ExpandableListActivity
MainActivity.java package com.example.mars_2300_expandablelist; import java.util.ArrayList; import j ...
- android ExpandableListActivity的使用
package com.example.keKuoZhanLieBiao; import android.app.ExpandableListActivity; import android.os.B ...
- listActivity和ExpandableListActivity的简单用法
http://www.cnblogs.com/limingblogs/archive/2011/10/09/2204866.html 今天自己简单的总结了listActivity和Expandable ...
- Android ExpandableListActivity的简单介绍及小例子
Android中常常要用到ListView,但也经常要用到ExpandableListView,ListView是显示列表,而ExpandableListView显示的是分类的列表: 下面用一个例子来 ...
- Android :ExpandableListActivity
http://developer.android.com/reference/android/app/ExpandableListActivity.html# public class Expanda ...
- Android ExpandableListActivity
======MainActivity.java===================================== package com.zys.myexpandablelistactivit ...
- ExpandableListActivity的基本使用方法 ,SimpleExpandableListAdapter的基本使用方法
activity_main.xml: <ExpandableListView android:id="@id/android:list" android:layout_wid ...
随机推荐
- input输入框type设置为number,maxlength无效
一个小细节,以前很少注意,直到最近做的一个项目,当我把一个输入数字的input框的类型设置为number时,input框还是可以无限输入,设置maxlengh=10就不起作用了.然后我就去百度了一下, ...
- duv中内容不换行的解决办法
<div style='width: 100px;display:block;word-break: break-all;word-wrap: break-word;'> 内容超出div宽 ...
- JDBC 通过读取文件进行初始化
- 《Web安全攻防 渗透测试实战指南》 学习笔记(一)
Web安全攻防 渗透测试实战指南 学习笔记 (一) 第一章 信息收集 在信息收集中,最重要是收集服务器的配置信息和网站敏感信息(域名及子域名信息目标网站系统.CMS指纹.目标网站真实I ...
- WLC Crash采集什么信息?
WLC和思科的路由器交换机不同,Cisco的WLC采用的是AireOS. 如果WLC crash或无故重启,可以尝试采集如下信息: AireOS WLC version 8.0.140.0 or hi ...
- lc 0219
目录 ✅ 463. 岛屿的周长 描述 解答 cpp py ✅ 1122. 数组的相对排序 描述 解答 cpp py ✅ 876. 链表的中间结点 描述 解答 cpp ✅ 1160. 拼写单词 描述 解 ...
- Educational Codeforces Round 81 (Rated for Div. 2)
A 0~9需要多少笔画,自取7和1,判奇偶 #include<bits/stdc++.h> using namespace std; #define ll long long #defin ...
- STM32cubeMX安装FW_F4容易出错失败的解决办法
在CUBEMXV5.30安装F4的支持包V1.241的反复失败,无法自动生成代码.后来发现了一种办法: 在stm32的官网下载V1.24.0和en.patch_cubefw_f4.zip(V1.24. ...
- JAVA 常用包
JAVA是以包的形式进行语言结构组织的. 引入这些包的关键词就是 import 下面说说 JAVA常用包有下面的几个 1. java.lang 这个是默认引入的,也是一个最基础的包.其中lang不是中 ...
- SVN 锁定无法提交命令执行失败
有个项目使用svn 高版本客户端作业,转换到低版本的环境下,出现锁定,命令执行失败. 使用cleanup 没有效果, 网上建议的svn无法Cleanup解决方法: Step1:到 sqlite官网 ( ...