Android ExpandableListView
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的更多相关文章
- 【开源项目4】Android ExpandableListView
如果你对Android提供的Android ExpandableListView并不满意,一心想要实现诸如Spotify应用那般的效果,那么SlideExpandableListView绝对是你最好的 ...
- 【原创】Android ExpandableListView使用
ExpandableView的使用可以绑定到SimpleExpandableListAdapter,主要是看这个Adapter怎么用. 这个类默认的构造函数有9个参数, 很好地解释了什么叫做又臭又长. ...
- 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和做项目,文章内容表达的不好或者理解错了,希望大家评论指出. :-) 本文是总结几个比较常用且使用的技巧,和一个大家都会遇到的问题. 文章中大部分语句摘抄 ...
- Android ExpandableListView 带有Checkbox的简单应用
expandablelistview2_groups.xml <?xml version="1.0" encoding="utf-8"?> < ...
- Android ExpandableListView的简单应用
Expandablelistview1Activity.java package com.wangzhu.demoexpandablelistview; import java.util.ArrayL ...
- Android ExpandableListView使用+获取SIM卡状态信息
ExpandableListView 是一个可以实现下拉列表的控件,大家可能都用过QQ,QQ中的好友列表就是用ExpandableListView实现的,不过它是自定义的适配器.本篇 博客除了要介绍E ...
随机推荐
- 安装一些包管理的记录 win10
我大php的composer 国内镜像包http://pkg.phpcomposer.com/ 还是全局的爽些: omposer config -g repo.packagist composer ...
- Fedora 21 64位系统安装WPS教程
WPS的Linux版本的出现简直是Linux党的福音,Ubuntu上的WPS安装非常简单,但是在Fedora上却有点小麻烦.主要是库的依赖问题.下面记录一下Fedora 21的64位版安装WPS的完整 ...
- Coursera Machine Learning : Regression 评估性能
评估性能 评估损失 1.Training Error 首先要通过数据来训练模型,选取数据中的一部分作为训练数据. 损失函数可以使用绝对值误差或者平方误差等方法来计算,这里使用平方误差的方法,即: (y ...
- Spark standalone HA
配置Spark standalone HA 主机:node1,node2,node3 master: node1,node2 slave:node2,node3 修改配置文件: node1,node3 ...
- 3.使用git提交项目到开源中国(gitosc)
1.提交地址 使用的是开源中国git仓库 git.oschina.net 在windos环境下使用msysgit. 2.初始化化 username.email初始化 git config --glob ...
- iOS.ReactNative-3-about-viewmanager-uimanager-and-bridgemodule
RCTViewManager and RCTUIManager 1. RCTViewManager 1.1 RCTViewManager 实现了接口RCTBridgeModule @interface ...
- linux服务器apache 一个IP,一个端口,建立多个网站的方法。
找到apache-tomcat-6.0.14\conf\server.xml ,再services 后面添加此段代码: Xml代码 <!-- 此处 新增的项目配置--> <Ser ...
- JAVA多线程 问题 转载
参考:http://ifeve.com/java-multi-threading-concurrency-interview-questions-with-answers/ http://www.cn ...
- Daily Scrum 12.17
今日完成任务: 解决匿名回答时候字数限制问题:完善了用户界面的UI设计: 明日任务: 孙思权 接口设计 晏旭瑞 资源索引问题 冯飘飘 解决上传资源时候不勾选或不添加选项内容可以上传的问题 黎柱金 进行 ...
- 用jquery编写的分页插件
用jquery编写的分页插件 源码 function _pager_go(total_page) { var page_str = $("#_pager_textbox").val ...