ExpandableListView的使用
ExpandableListView的使用
效果图
布局
<ExpandableListView
android:id="@+id/expandableListView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
初始化
ExpandableListView expandableListView = (ExpandableListView) findViewById(R.id.expandableListView);
填充数据
KongqwExpandableListviewAdapter kongqwExpandableListviewAdapter = new KongqwExpandableListviewAdapter(this);
expandableListView.setAdapter(kongqwExpandableListviewAdapter);
Adapter
package com.example.kongqw.myapplication;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;
import java.util.ArrayList;
/**
* Created by kongqw on 2015/12/21.
*/
public class KongqwExpandableListviewAdapter extends BaseExpandableListAdapter {
private Context mContext;
private ArrayList<String> mGroups;
private ArrayList<String> mChilds;
// 构造方法
public KongqwExpandableListviewAdapter(Context context) {
mContext = context;
// 模拟初始化数据
mGroups = new ArrayList<String>();
mGroups.add("Group 1");
mGroups.add("Group 2");
mGroups.add("Group 3");
mGroups.add("Group 4");
mGroups.add("Group 5");
mChilds = new ArrayList<String>();
mChilds.add("Child 1");
mChilds.add("Child 2");
mChilds.add("Child 3");
mChilds.add("Child 4");
mChilds.add("Child 5");
mChilds.add("Child 6");
mChilds.add("Child 7");
mChilds.add("Child 8");
mChilds.add("Child 9");
mChilds.add("Child 10");
}
@Override
public int getGroupCount() {
return mGroups.size();
}
@Override
public int getChildrenCount(int groupPosition) {
return mChilds.size();
}
@Override
public Object getGroup(int groupPosition) {
return mGroups.get(groupPosition);
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return mChilds.get(childPosition);
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
View view = View.inflate(mContext, R.layout.expandable_group_item, null);
TextView textView = (TextView) view.findViewById(R.id.group_item);
textView.setText(mGroups.get(groupPosition));
return view;
}
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
View view = View.inflate(mContext, R.layout.expandable_child_item, null);
TextView textView = (TextView) view.findViewById(R.id.child_item);
textView.setText(mChilds.get(childPosition));
return view;
}
@Override
public boolean hasStableIds() {
return true;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
去掉箭头
expandableListView.setGroupIndicator(null);
默认展开
// 设置ExpandableListView默认是展开的
for (int i = 0; i < kongqwExpandableListviewAdapter.getGroupCount(); i++) {
expandableListView.expandGroup(i);
}
Group不可点击
expandableListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
@Override
public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
// TODO Auto-generated method stub
return true;
}
});
TODO 复用
ExpandableListView的使用的更多相关文章
- Android中使用ExpandableListView实现微信通讯录界面(完善仿微信APP)
之前的博文<Android中使用ExpandableListView实现好友分组>我简单介绍了使用ExpandableListView实现简单的好友分组功能,今天我们针对之前的所做的仿微信 ...
- Android中使用ExpandableListView实现好友分组
一个视图显示垂直滚动两级列表中的条目.这不同于列表视图,允许两个层次,类似于QQ的好友分组.要实现这个效果的整体思路为: 1.要给ExpandableListView 设置适配器,那么必须先设置数据源 ...
- 安卓开发树形控件之ExpandableListView(一)
这个例子非常简单,简单到一个初学者都能随便开发出来,今天的目的仅仅只是为了将效果实现出来,如果想深入这里有几篇非常不错的博客: Android 之ExpandableListView几个特殊的属性 h ...
- android 伸缩控件ExpandableListView 展开失败的可能原因。
(原创)转载请声明出处http://www.cnblogs.com/linguanh/ 问题原型: ExpandableListView 展开失效. --------------------直接看结论 ...
- ExpandableListView实现展开更多和收起更多
[需求]: 如上面图示 当点开某个一级菜单的时候,其他菜单收起: 子级菜单默认最多5个: 多于5个的显示"展开更多" 点击"展开更多",展开该级所有子级菜单,同 ...
- Android UI控件----ExpandableListView的基本用法
ExpandableListView介绍 ExpandableListView的引入 ExpandableListView可以显示一个视图垂直滚动显示两级列表中的条目,这不同于列表视图(ListVie ...
- 【原创】Android ExpandableListView使用
ExpandableView的使用可以绑定到SimpleExpandableListAdapter,主要是看这个Adapter怎么用. 这个类默认的构造函数有9个参数, 很好地解释了什么叫做又臭又长. ...
- android原生ExpandableListView
android原生可扩展ExpandableListView就是可以伸缩的listView,一条标题下面有多条内容. 这个list的adapter对的数据要求与普通ListView的数据要求也有一些差 ...
- 可滑动的ExpandableListView
可以向左滑动的扩展列表 向左滑动源码是参照GitHub上的里的 ListView的思路写出来的,按照他的思路,由于本人水平有限,只写了关键代码,能够完美运行,adapter改变之后能自动收回. 滑出状 ...
- Android中ExpandableListView的使用
ExpandableListView是Android中可以实现下拉list的一个控件,具体的实现方法如下: 首先:在layout的xml文件中定义一个ExpandableListView < L ...
随机推荐
- Hadoop 3.x 新特性剖析系列1
1.概述 目前从Hadoop官网的Wiki来看,稳定版本已经发行到Hadoop2.9.0,最新版本为Hadoop3.1.0,查阅JIRA,社区已经着手迭代Hadoop3.2.0.那么,今天笔者就带着大 ...
- Javascript闭包(Closure)
1.Javascript特殊的变量作用域.变量的作用域无非就是两种:全局变量和局部变量.Javascript语言的特殊之处,就在于函数内部可以直接读取全局变量. function f1() { var ...
- drupal8的安装
一.首先安装好linux系统虚拟机 1.在drupal官网上下载drupal包,https://www.drupal.org/download 我下载的是 https://ftp.drupal.org ...
- 2015 多校联赛 ——HDU5325(DFS)
Crazy Bobo Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Tota ...
- Codeforces Round #402 (Div. 1)
A题卡壳了,往离线倒着加那方面想了会儿,后来才发现方向错了,二十多分钟才过掉,过了B后做D,想法好像有点问题,最后只过两题,掉分了,差一点回紫. AC:AB Rank:173 Rating:2227- ...
- python dataframe数据条件筛选
一般情况下我们从一堆数据中选择我们获取想要的数据会通过一下方式: (1)创建链表或数组: (2)用for 循环遍历所有数据,将想要的存入链表或数组. 但是python中我们不需要这么做,我们可以用Pa ...
- 笔记7 AOP
1. 通知(Advice) 切面的工作被称为通知.通知定义了切面是什么以及何时使用.除了描述切面要完成的工作, 通知还解决了何时执行这个工作的问题.它应该应用在某个方法被调 用之前?之后?之前和之 ...
- ELK 6.2.4搭建
开源实时日志分析ELK平台能够完美的解决我们上述的问题,ELK由ElasticSearch.Logstash和Kiabana三个开源工具组成.官方网站:https://www.elastic.co/p ...
- vue+cordova 构建hybrid app
配了一个 vue + cordova + ionicCli 的 项目 支持 ionic 的脚手架命令 支持 cordova 的 插件 安装使用 支持 webpack 的自动构建 vue 安装了 vue ...
- 原生js移动端列表无缝间歇向上滚动
在项目开发中尤其是在项目的活动页面的开发中,经常需要将用户的购买信息或中奖信息等以列表的形式展示在页面当中,并可以使其自动间歇向上滚动来达到在有限的区域内展示所有信息的目的.通常的做法是通过将列表父元 ...