【原创】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和做项目,文章内容表达的不好或者理解错了,希望大家评论指出. :-) 本文是总结几个比较常用且使用的技巧,和一个大家都会遇到的问题. 文章中大部分语句摘抄 ...
随机推荐
- ZeroMQ接口函数之 :zmq_null - 无安全和加密
ZeroMQ 官方地址 :http://api.zeromq.org/4-2:zmq_null zmq_null(7) ØMQ Manual - ØMQ/4.1.0 Name zmq_null - 无 ...
- EaseMode
The following graphs demonstrate the different values of EasingMode, where f(t) represents the anima ...
- 如何获取hibernate代理类代理的实际对象实例?
在hibernate中,通过sql语句查询带clob字段的记录,查出来的结果集是List<HashMap<String,Object>>类型,在调用jackson的接口转为js ...
- Spring中Bean的作用域
1.在Spring的早期版本中,仅有两个作用域:singleton和prototype,前者表示Bean以单例的方式存在:后者表示每次从容器中调用Bean时,都会返回一个新的实例 2.Spring 2 ...
- Visual Studio 2010编译时总是提示"调用目标发生了异常"的解决
现象: 无论建立的是Win32 Console的解决方案,还是MFC的解决方案,重新打开Visual Studio 2010之后,编译时总是提示“调用的目标发生了异常” 解决: 1. 关闭Visual ...
- 如何用shared_ptr减少锁的争用
在并发环境下锁的使用是家常便饭, 如何减少锁的使用是优化程序性能的一个方面. c++11里面新增了智能指针std::shared_ptr, 这个东西也许能给我们带来些启发. shared_ptr的一个 ...
- JBoss QuickStart之Helloworld
下载Jboss, quickstart, 按照quickstart说明, mvn clean install. 由于ssl handshake问题(应该是网络连接不稳定), 写了一个脚本不停地尝试bu ...
- java synchronized详解
Java语言的关键字,当它用来修饰一个方法或者一个代码块的时候,能够保证在同一时刻最多只有一个线程执行该段代码. 一.当两个并发线程访问同一个对象object中的这个synchronized(this ...
- 毕业设计 之 二 PHP学习笔记(一)
毕业设计 之 二 PHP学习笔记(一) 作者:20135216 平台:windows10 软件:XAMPP,DreamWeaver 一.环境搭建 1.XAMPP下载安装 XAMPP是PHP.MySQL ...
- 远程连接服务器for Linux
远程连接Linux云服务器-命令行模式 1.远程连接工具.目前Linux远程连接工具有很多种,您可以选择顺手的工具使用.下面使用的是名为Putty的Linux远程连接工具.该工具是免费的,且不需要安装 ...