ExpandableListView 结合SimpleExpandableListAdapter用法

最终实现效果:

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.zy.expandablelistview.MainActivity"> <ExpandableListView
android:id="@+id/expand_list_view"
android:layout_width="match_parent"
android:layout_height="match_parent"> </ExpandableListView>
</RelativeLayout>

父级布局文件group_item.xml

<?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:gravity="center_vertical" android:orientation="vertical"> <TextView
android:id="@+id/tv_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content" /> </LinearLayout>

子级布局文件child_item.xml

<?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:paddingLeft="30dp"
android:gravity="center_vertical"
android:orientation="vertical"> <TextView
android:id="@+id/tv_child"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>

MainActivity.java

package com.zy.expandablelistview;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ExpandableListView;
import android.widget.SimpleExpandableListAdapter; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map; public class MainActivity extends AppCompatActivity { List<Map<String,?>> groupList = new ArrayList<>();
List<List<Map<String,String>>> itemList = new ArrayList<>();
String[] groupStringArr = {"腾讯","百度","阿里巴巴"};
String[][] itemStringArr = {
{"QQ","腾讯云服务","QQ浏览器"},
{"百度地图","百度搜索","百度外卖"},
{"淘宝","天猫","阿里云"}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ExpandableListView expandableListView = (ExpandableListView) findViewById(R.id.expand_list_view); //父级数组
for (int i = 0; i < groupStringArr.length; i++) {
Map<String,String> gMap = new HashMap<>();
gMap.put("groupName",groupStringArr[i]);
groupList.add(gMap);
//子级数组
List<Map<String,String>> itemFor = new ArrayList<>();
for (int j = 0; j < itemStringArr[i].length; j++) {
Map<String,String> iMap = new HashMap<>();
iMap.put("itemName",itemStringArr[i][j]);
itemFor.add(iMap);
}
itemList.add(itemFor);
} SimpleExpandableListAdapter simpleExpandableListAdapter = new SimpleExpandableListAdapter(this,
groupList,R.layout.group_item,new String[]{"groupName"},new int[]{R.id.tv_group},
itemList,R.layout.child_item,new String[]{"itemName"},new int[]{R.id.tv_child}); expandableListView.setAdapter(simpleExpandableListAdapter);
}
}

Android ExpandableListView的更多相关文章

  1. 【开源项目4】Android ExpandableListView

    如果你对Android提供的Android ExpandableListView并不满意,一心想要实现诸如Spotify应用那般的效果,那么SlideExpandableListView绝对是你最好的 ...

  2. 【原创】Android ExpandableListView使用

    ExpandableView的使用可以绑定到SimpleExpandableListAdapter,主要是看这个Adapter怎么用. 这个类默认的构造函数有9个参数, 很好地解释了什么叫做又臭又长. ...

  3. android ExpandableListView详解

    ExpandableListView是android中可以实现下拉list的一个控件,是一个垂直滚动的心事两个级别列表项手风琴试图,列表项是来自ExpandableListViewaAdapter,组 ...

  4. 解决android expandablelistview 里面嵌入gridview行数据重复问题

    最近做了一个“csdn专家博客App” 当然了是android版本,在专家浏览页面,我才用了expandablelistview 组件来显示专家分类,每个分类点击之后可以显示专家的头像和名字. 很简单 ...

  5. Android ExpandableListView的下拉刷新实现

    该控件的修改时根据PullToRefreshList的机制修改 下面是对ExpandableListView的扩展 package com.up91.gwy.view.componet; import ...

  6. Android ExpandableListView的技巧和问题

    前言: 最近一个多月在认真的学习Android和做项目,文章内容表达的不好或者理解错了,希望大家评论指出. :-) 本文是总结几个比较常用且使用的技巧,和一个大家都会遇到的问题. 文章中大部分语句摘抄 ...

  7. Android ExpandableListView 带有Checkbox的简单应用

    expandablelistview2_groups.xml <?xml version="1.0" encoding="utf-8"?> < ...

  8. Android ExpandableListView的简单应用

    Expandablelistview1Activity.java package com.wangzhu.demoexpandablelistview; import java.util.ArrayL ...

  9. Android ExpandableListView使用+获取SIM卡状态信息

    ExpandableListView 是一个可以实现下拉列表的控件,大家可能都用过QQ,QQ中的好友列表就是用ExpandableListView实现的,不过它是自定义的适配器.本篇 博客除了要介绍E ...

随机推荐

  1. Ajax调用SpringMVC ModelAndView 无返回情况

    在项目中使用Ajax的时候,success中返回的data一直都是null,也没有报错.在确定Ajax语法没有错误,也没有牵扯跨域问题后,用排除法挨着删除代码,发现是因为Spring MVC会自动把方 ...

  2. 09-JAVA中的异常处理

    1. 程序执行结果: 也就是它根本就没抛出异常,更别提捕获异常了.那么,为什么会这样呢? 原来, 如上面程序展示,程序运行到k=i/j;的时候,就会直接终止,根本就不会运行到监视的程序,更不会运行到捕 ...

  3. 【转】oracle查询用户表,函数,储存过程,

    ◆Oracle查询用户表空间:select * from user_all_tables ◆Oracle查询所有函数和储存过程:select * from user_source ◆Oracle查询所 ...

  4. Servlet过滤器(详询请加qq:2085920154)

    1.1  过滤器简介 过滤器是向Web应用程序的请求和响应处理添加功能的Web服务组件.在Servlet处理用户输入的请求之前,过滤器可以访问该请求.在将Web响应发送给用户之前,过滤器还可以访问该响 ...

  5. AdminLTE-2.2.0 学习

    这货基于Bootstrap 3(提供了统一的样式,覆盖了默认的),所以官方建议先搞懂Bootstrap 3再说. # 布局 Layout 布局由四个主要部分组成: Wrapper (.wrapper) ...

  6. 学习总结relative和absolute

    之前对于absolute和relative不了解,现在整理 先设置relative再设置absolute 因为父不设置relative 那么子会向上寻找祖先元素,看是否设置relative.如果有则相 ...

  7. .Net MVC+bootstrap Table学习

    一.效果展示 二.使用方法 1).相关css和js的引用 <link href="~/Themes/Bootstrap/css/bootstrap.css" rel=&quo ...

  8. 一个sendMessage

    Message 1.判断是否同意协议.2.验证验证码是否正确.3.验证手机是否符合规则,符合规则就用message()发送短信,验证码的有效期以及使用的短信模板,在配置文件中进行管理.返回值下标为st ...

  9. Linux系统目录结构

    Linux系统目录结构图 目录:/ 是Linux的根目录 每个文件和目录从根目录开始,只有root用户具有该目录下的写权限: /root是root用户的主目录,这与 / 目录不一样: 目录:/bin ...

  10. 17.iOS App设置icon,启动图,App名称的方法

    icon:选择Assets-->AppIcon-->将各种尺寸的icon拖拽到相应的框中. APP名称:选择info-->Bundle name,修改APP名字. 启动图: 首先点击 ...