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 ...
随机推荐
- MySQL协议学习(1):准备工作
MySQL Client/Server协议 准确的说应该是MySQL Client/Server协议,另一个叫X Protocol的暂不涉及.地址如下:MySQL Client/Server Prot ...
- jQuery的ajax学习
jQuery是一个非常常见的JavaScript库,可是,突然发现其实自己大多数时候,潜意识里面对它其实是视而不见的,比如它的ajax,不是没用过,每次使用,要不,是直接套用已有的格式,要不直接从官网 ...
- “百度杯”CTF比赛 九月场_再见CMS(齐博cms)
题目在i春秋ctf大本营 又是一道cms的题,打开御剑一通乱扫,发现后台登录地址,访问一看妥妥的齐博cms 记得以前很久以前利用一个注入通用漏洞,这里我贴上链接,里面有原理与利用方法详细说明: 齐博c ...
- burp的dns记录功能
写个备忘. 先点copy复制url,然后生成的url就能用了. 一关就没了,比较鸡肋些,不适合持久的,适合马上就能见效果的那种.
- [USACO14DEC]后卫马克Guard Mark
题目描述 FJ将飞盘抛向身高为H(1 <= H <= 1,000,000,000)的Mark,但是Mark 被N(2 <= N <= 20)头牛包围.牛们可以叠成一个牛塔,如果 ...
- 【NOIP2015TG】solution
链接:https://www.luogu.org/problem/lists?name=&orderitem=pid&tag=83%2C32 D1T1(magic) 题意:看题目.. ...
- Codeforces Round #452 F. Letters Removing
Description Petya has a string of length n consisting of small and large English letters and digits. ...
- 【Uva 10269 马里奥与公主的归途】
·马里奥n次解救了公主,现在需要从魔王的宫殿返回. ·英文题,述大意: 给定一个点数不超过100的无向图,其中的点分为两类:乡村和城堡. 输入A个乡村,B个城堡(乡村编号1~A,城堡编号A+ ...
- [bzoj4850][Jsoi2016]灯塔
来自FallDream的博客,未经允许,请勿转载,谢谢. JSOI的国境线上有N一座连续的山峰,其中第ii座的高度是hi??.为了简单起见,我们认为这N座山峰排成了连续一条 直线.如果在第ii座山峰上 ...
- CSS3中三种清除浮动(float)的方法
方法一:添加新的元素 .应用 clear:both .clear{ clear:both; height:; height:; overflow:hidden; } 方法二:父级div定义 overf ...