ExpandableListActivity列表嵌套列表
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<ExpandableListView
android:id="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false"/>
<TextView
android:text="No Data"
android:id="@id/android:empty"
android:layout_height="fill_parent"
android:layout_width="fill_parent"/>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:text="No Data" android:id="@+id/textView_group" android:layout_height="fill_parent" android:layout_width="fill_parent" android:paddingLeft="60dp" android:paddingTop="10dp" android:textSize="25dp">
</TextView>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical">
<TextView android:text="No Data" android:layout_width="fill_parent"
android:id="@+id/textView_child" android:layout_height="fill_parent" android:paddingLeft="40dp" android:paddingTop="15dp" android:textSize="20dp" android:paddingBottom="5dp"></TextView>
</LinearLayout>
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 {
/** ExpandableListActivity列表嵌套列表---->MainActivity继承了ExpandableListActivity */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// 数据的准备构成
// 列表分2大类
//定义一个list,该list对象为一级条目提供数据,次代码为两个list条目
List<Map<String, String>> groups = new ArrayList<Map<String, String>>();
Map<String, String> group1 = new HashMap<String, String>();
group1.put("group", "group1");
groups.add(group1);
Map<String, String> group2 = new HashMap<String, String>();
group2.put("group", "group2");
groups.add(group2);
// 每类有2组数据
//定义一个list,该list对象为第一个一级条目提供二级条目数据,次代码为两个list条目
List<Map<String, String>> child1 = new ArrayList<Map<String, String>>();
Map<String, String> child1_1 = new HashMap<String, String>();
child1_1.put("child", "child1");
child1.add(child1_1);
Map<String, String> child1_2 = new HashMap<String, String>();
child1_2.put("child", "child2");
child1.add(child1_2);
// 定义一个list,该list对象为第二个一级条目提供二级条目数据
List<Map<String, String>> child2 = new ArrayList<Map<String, String>>();
Map<String, String> child2_1 = new HashMap<String, String>();
child2_1.put("child", "child1");
Map<String, String> child2_2 = new HashMap<String, String>();
child2_2.put("child", "child2");
child2.add(child2_1);
child2.add(child2_2);
List<List<Map<String, String>>> childs = new ArrayList<List<Map<String, String>>>();
childs.add(child1);
childs.add(child2);
// SimpleExpandableListAdapter向ExpandableListActivity推送数据
//new String[] { "group" },new int[] { R.id.textView_group }这两个参数为一级条目的键值对
SimpleExpandableListAdapter simpleExpandableListAdapter = new SimpleExpandableListAdapter(
this, groups, R.layout.group, new String[] { "group" },
new int[] { R.id.textView_group }, childs, R.layout.child,
new String[] { "child" }, new int[] { R.id.textView_child });
setListAdapter(simpleExpandableListAdapter);
}
}
转载于:https://blog.51cto.com/haiyuanxi/961166
ExpandableListActivity列表嵌套列表相关推荐
- python列表的嵌套_Python中关于列表嵌套列表的处理
在处理列表的时候我们经常会遇到列表中嵌套列表的结构,如果我们要把所有元素放入一个新列表,或者要计算所有元素的个数的话应该怎么做呢? 第一个例子 对于上图中的这样一组数据,如果我们要知道这个CSV文件中 ...
- 使用Typora列表嵌套列表,回车无法返回上一级列表的状态
问题 使用Typora列表嵌套列表,回车无法返回上一级列表的状态,只能换行 原因或解决 光标后还存在一个或多个空行,无论怎么回车,都被认得为还是在内列表里 光标点在最后一行或使用快捷键Ctrl + E ...
- python列表操作——列表嵌套列表,找出嵌套列表中共同的元素
今天在项目中遇到了一个列表嵌套找出共同元素的问题,本来懒得造轮子,直接百度一波,查了一圈不是只有两个list就是使用Intersection这个函数,可能这个功能过于简单了没人写,我试着用Inters ...
- 列表嵌套的元组改成列表嵌套列表
##### 索引元组在列表中的位置,再通过列表中的位置访问元组,有意思,index函数用于访问位置,卧槽!成功了卧槽卧槽 lst = [(1,1),(2,2),(3,3)] for i in lst: ...
- python列表用法详解(查找、添加、删除、修改、复制、循环遍历、列表嵌套)
1. 列表的格式 [数据1, 数据2, 数据3, 数据4......] 列表可以⼀次性存储多个数据,且可以为不同数据类型. 2. 列表的常⽤操作 列表的作⽤是⼀次性存储 ...
- Python拆开嵌套列表元组
拆开一层 利用functools.reduce()或itertools.chain.from_iterable() import functoolsdef list_unpack(l):"& ...
- python列表嵌套字典取值_Python零基础快速入门(五):列表和字典
第5节课程大纲 一.数据类型:列表 1.什么是列表 2.从列表提取单个元素:偏移量 3.从列表提取多个元素:冒号切片 4.给列表增加/删除元素:append()函数 二.数据类型:字典 1.什么是字典 ...
- android优雅的解决列表嵌套 类似订单列表这种
常见问题,类似订单列表这种,每个大item,有相同布局,但有些头部和底部View没办法根据数据类型复用,如下图.很多人采用列表嵌套列表来做,但这样会造成UI卡顿,因为滑动的时候外层列表的Item需不断 ...
- python读取json格式文件大量数据,以及python字典和列表嵌套用法详解
1.Python读取JSON报错:JSONDecodeError:Extra data:line 2 column 1 错误原因: JSON数据中数据存在多行,在读取数据时,不能够单单用open(), ...
最新文章
- 点分治问题 ----------- HDU6881 Tree Cutting or 2020杭电多校第10场 [点分治+思维]
- 高盛5年来首次看好中国互联网利润
- 【分享】【养生】消灭小肚腩
- 第四范式与丘成桐北京雁栖湖应用数学研究院签署战略合作协议
- java求面积_Java之简单图形面积计算
- LinkedList类源码浅析(二)
- FM算法及FFM算法
- 2013北理机试题——中缀算术表达式对应二叉树的先序遍历
- android 红外遥控程序,Android 红外遥控器适配
- QQ和MSN 在线代码
- PROFINET的时钟同步(一)
- activex服务器与com组件,COM和ActiveX控件设计.ppt
- Unity3D基础数学向量
- Java验证中文汉字、英文字母、标点符号一个字符占多少字节
- 4T移动硬盘 分区_手机连接移动硬盘教程
- 【JAVA EE#6】【传智书城·源码阅读】后台管理模块:权限控制+页面分析+商品管理+销售榜单+订单管理+公告管理+项目结构思维导图
- 爱快 Open v服务端 全局推送路由器命令
- SM2262EN+东芝BICS3 1TB开卡报错处理
- 《计算机绘图》期末试卷d,计算机绘图试卷
- 【紧急】Log4j又发新版2.17.0,只有彻底搞懂漏洞原因,才能以不变应万变
热门文章
- 为何在wpf中textbox的值有时不会实时的变化
- 一个封装比较完整的FTP类——clsFTP
- 使用MONO使.net程序脱离.net框架运行
- Ubuntu终端(terminal)及Thunderbird邮件客户端常用的快捷键
- 最大的路径的节点值之和
- 关于python文件操作
- MongoDB基本概念和常用操作(一)
- LeetCode 4. Median of Two Sorted Arrays
- 【AI视野·今日CV 计算机视觉论文速览 第160期】Wed, 25 Sep 2019
- 【今日CS 视觉论文速览】Mon, 14 Jan 2019