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. highcharts曲线图

    在做项目时,用highcharts做过曲线图,X轴是从后台获取的时间数据,Y轴是从后台获取的Int型数据 1.我的后台数据封装成json格式,数据较多,展示部分数据 2.曲线图的展示 3.前端jsp页 ...

  2. XUtils——GET请求

    //HttpUtils实例化对象     HttpUtils http = new HttpUtils();       /*                *发送请求send(HttpMethod ...

  3. with try catch 作用域的问题

    with({}){}和try{}catch(e){}会临时改变代码执行的作用域, var foo="abc"; with({foo:"d"}){ functio ...

  4. Calculating Stereo Pairs

    Calculating Stereo Pairs Written by Paul BourkeJuly 1999 Introduction The following discusses comput ...

  5. PD中将Comment 从Name复制值

    PD中将Comment 从Name复制值, 将以下语句考到,pd 工具栏下的执行脚本中执行下就OK了 Option Explicit ValidationMode = True Interactive ...

  6. Spark简介

    Spark是UC Berkeley AMP lab所开源的类Hadoop MapReduce的通用并行框架,Spark,拥有Hadoop MapReduce所具有的优点:但不同于MapReduce的是 ...

  7. javascript除法如何取整

    Math.round(x) 四舍五入,如Math.round(0.60),结果为1:Math.round(0.49),结果为0: Math.floor(x) 向下舍入,如Math.floor(0.60 ...

  8. 【Mail】JavaMail介绍及发送邮件(一)

    JavaMail介绍 JavaMail是SUN提供给开发人员在应用程序中实现邮件发送和接收功能而提供的一套标准开发类库,支持常用的邮件协议,如SMTP.POP3.IMAP,开发人员使用JavaMail ...

  9. Echarts给柱状图每一条顶部都添加数值

    在 series中添加 itemStyle : { normal: {label : {show: true}}}, 不过目测要把markPoint等去掉,不然最大值和最小值会和label冲突,应该有 ...

  10. Cauchy 级数浓缩判别法