【原创】Android ExpandableListView使用
public SimpleExpandableListAdapter (Context context, List<? extends Map<String, ?>> groupData, int groupLayout, String[] groupFrom, int[] groupTo, List<? extends List<? extends Map<String, ?>>> childData, int childLayout, String[] childFrom, int[] childTo)
不过不用担心, 只要把Group开头的和Child开头的分成两组来看就好。 具体看下面注释部分。
可以采用对groupData和childData进行操作后再调用 ArrayAdapter.notifyDataSetChanged()方法来通知UI进行更新。
另外,还有一种操作group和child的方法是使用SimpleExpandableListAdapter的 getGroup和getChild方法。
public class MainActivity extends AppCompatActivity { /* 用四个group*数据来表示Group的表现方式,用四个child*的数据来表示Child的表示方式。
groupData,其中的每一个Map代表了一个Group的所有要显示的数据,比如在GroupTab上你想显示name,type,description,那么就在Map里面用键值对放这几项就好了。
groupLayout,只是一个视图,其中要包含有所有用于显示name,type,description等项目的元素。这些元素需要被放在groupTo里面。并且顺序要和groupFrom里面的key顺序对应。
groupFrom,要显示的Group数据的key。
groupTo,要显示的Group数据对应的View的ID。这些ID必须是之前定义的group布局里面的。 Child基本上类似,也是每一个Map对应一个Child的所有数据项。第一层List,分到不同的Group,第二层List,分到不同的ChildItem,第三层就是Map了,每个Child的数据集合。
**/ //定义Group相关变量
ArrayList<Map<String, String>> groupData = new ArrayList<>();
int groupLayout = R.layout.group_view_group;
String[] groupFrom = {"name", "type", "description"};
int[] groupTo = {R.id.txt_view_name, R.id.txt_view_type, R.id.txt_view_description};
//定义Child相关变量
ArrayList<ArrayList<Map<String, String>>> childData = new ArrayList<>();
int childLayout = R.layout.group_view_child;
String[] childFrom = {"ability"};
int[] childTo = {R.id.txt_view_child_ability};
//定义Adapter
SimpleExpandableListAdapter mArrayAdapter; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ExpandableListView list = (ExpandableListView) findViewById(R.id.expand_list); for (int i = 0; i < 3; i++) {
//初始化group数据
HashMap<String, String> map = new HashMap<>();
map.put("name", "device " + String.valueOf(i));
map.put("type", "type " + String.valueOf(i));
map.put("description", "Description of device " + String.valueOf(i));
groupData.add(map);
//初始化Child数据
ArrayList<Map<String, String>> childDataList = new ArrayList<>();
for (int j = 0; j < 4; j++) {
HashMap<String, String> tmpMap = new HashMap<String, String>();
tmpMap.put("ability", "ability " + String.valueOf(i) + String.valueOf(j));
childDataList.add(tmpMap);
}
childData.add(childDataList);
}
mArrayAdapter = new SimpleExpandableListAdapter(this, groupData, groupLayout, groupFrom, groupTo, childData, childLayout, childFrom, childTo);
list.setAdapter(mArrayAdapter);
} private void clearData() {
groupData.clear();
childData.clear();
mArrayAdapter.notifyDataSetChanged();
}
}
GroupView:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@android:color/holo_blue_light"
android:orientation="horizontal"> <TextView
android:id="@+id/txt_view_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:textSize="20dp" /> <LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"> <TextView
android:id="@+id/txt_view_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp" /> <TextView
android:id="@+id/txt_view_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp" />
</LinearLayout>
</LinearLayout>
ChildView:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="30dp"
android:orientation="vertical"> <TextView
android:id="@+id/txt_view_child_ability"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textSize="18dp" />
</LinearLayout>
【原创】Android ExpandableListView使用的更多相关文章
- 【开源项目4】Android ExpandableListView
如果你对Android提供的Android ExpandableListView并不满意,一心想要实现诸如Spotify应用那般的效果,那么SlideExpandableListView绝对是你最好的 ...
- [原创]Android Monkey 在线日志分析工具开发
[原创]Android Monkey 在线日志分析工具开发 在移动App测试过程中,Monkey测试是我们发现潜在问题的一种非常有效手段,但是Android原生的Monkey有其天然的不足,数据不能有 ...
- [原创]Android 常用adb命令总结
[原创]Android 常用adb命令总结 1 adb介绍 1.1 adb官方网站及下载 官方网站下载安装:http://adbshell.com/downloads 1.2 adb安装是否成功检查? ...
- [原创]Android Monkey测试工具使用介绍
[原创]Android Monkey测试工具使用介绍 1 Android Monkey介绍 Monkey是Android中的一个命令行工具,可以运行在模拟器里或实际设备中.它向系统发送伪随机的用户事件 ...
- Android ExpandableListView
ExpandableListView 结合SimpleExpandableListAdapter用法 最终实现效果: activity_main.xml <?xml version=" ...
- android ExpandableListView详解
ExpandableListView是android中可以实现下拉list的一个控件,是一个垂直滚动的心事两个级别列表项手风琴试图,列表项是来自ExpandableListViewaAdapter,组 ...
- 解决android expandablelistview 里面嵌入gridview行数据重复问题
最近做了一个“csdn专家博客App” 当然了是android版本,在专家浏览页面,我才用了expandablelistview 组件来显示专家分类,每个分类点击之后可以显示专家的头像和名字. 很简单 ...
- Android ExpandableListView的下拉刷新实现
该控件的修改时根据PullToRefreshList的机制修改 下面是对ExpandableListView的扩展 package com.up91.gwy.view.componet; import ...
- Android ExpandableListView的技巧和问题
前言: 最近一个多月在认真的学习Android和做项目,文章内容表达的不好或者理解错了,希望大家评论指出. :-) 本文是总结几个比较常用且使用的技巧,和一个大家都会遇到的问题. 文章中大部分语句摘抄 ...
随机推荐
- Mysql创建新用户方法
1. CREATE USER 语法: CREATE USER 'username'@'host' IDENTIFIED BY 'password'; 例子: CREATE USER 'dog'@'lo ...
- Web用户的身份验证及WebApi权限验证流程的设计和实现
5. WebApi 服务端代码示例 5.1 控制器基类ApiControllerBase [csharp] view plaincopy /// /// Controller的基类,用于实现适合业 ...
- onselectstart="return false"
以前在做图片滚动时,在双击左右箭头,快速切换图片滚动时,会选择附近区域的文字,感觉不是很好,今天在查资料时,讲到了这个问题, 试了一下,不错,解决了问题. IE及Chrome下的方法一样,对相应的元素 ...
- python中文注释报错问题
错误信息: SyntaxError: Non-ASCII character '\xe4' in file... 解决办法: 在文件第一行或第二行添加:# -*- coding: utf-8 -*- ...
- odoo 人力资源工资计算拓展
默认情况下 odoo工资条的计算只支持一下几种python变量: # payslip: object containing the payslips# employee: hr.employee ob ...
- NGUI实现技能CD效果
在NGUI中使用Sprite的遮罩效果可以很轻松的实现技能CD效果. 具体实现步骤: ①新建一个技能图标的Sprite 如图中的Skill001,再在该技能Sprite上添加一个Sprite做遮罩, ...
- 谢欣伦 - OpenDev原创教程 - 客户端套接字类CxClientSocket
这是一个精练的客户端套接字类,类名.函数名和变量名均采用匈牙利命名法.小写的x代表我的姓氏首字母(谢欣伦),个人习惯而已,如有雷同,纯属巧合. CxClientSocket的使用如下(以某个叫做CSo ...
- nginx 不带www到www域名的重定向
如果是单次重定向用 redirect, 如果永久跳转用 permanent,这里用 permanent { listen 80; server_name xxx.com www.xxx. ...
- Spark会把数据都载入到内存么
转载自:https://www.iteblog.com/archives/1648 前言: 很多初学者其实对于Spark的编程模式还是RDD这个概念理解不到位,就会产生一些误解.比如,很多时候我们常常 ...
- bmp图片的有关操作
读取bmp图片 并生成新的bmp图片 #include "stdafx.h"#include <windows.h>#include <cmath>#inc ...