Android之可收缩展开列表ExpandableList
来源:互联网 发布:手机流量统计软件 编辑:程序博客网 时间:2024/04/28 05:00
在Android的app包中,有这么一个类,这个类继承自Activity,它叫ExpandableListActivity。顾名思义,从它的名字可以看出该类是一种可扩展性的列表List,我们这里理解成可伸缩的列表,也就是通过继承ExpandableListActivity可以实现列表的可展开/收缩的功能。
本文我们主要介绍这种列表的显示是如何实现的,在ListActivity的使用中,我们知道一旦继承了ListActivity,该类就意味这具备了List的功能,同样的,我们将一个类继承了ExpandableListActivity,就可以直接调用该类本身的ExpandableList对象,并直接赋予一个自定义的适配器setListAdapter(adapter);,因此,整个实现的重心放在如何设计这个适配器上面,以下是适配器的一个举例。
public class mExpandableListAdapter extendsBaseExpandableListAdapte
// 父列表数据
private String[] groups =
{
“随时随地”,
“即兴时代”,
“ATAAW.COM”,
};
// 子列表数据
private String[][] children =
{
{ “即兴” },
{ “随时随地”, “即兴时代” },
{ “随时随地”, “即兴时代”, “ATAAW.COM” },
};
@Override
public Object getChild(int groupPosition, int childPosition){
return children[groupPosition][childPosition];
}
@Override
public long getChildId(int groupPosition, int childPosition){
return childPosition;
}
@Override
public int getChildrenCount(int groupPosition) {
return children[groupPosition].length;
}
// 取子列表中的某一项的 View
@Override
public View getChildView(int groupPosition, intchildPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
TextView textView = getGenericView();
textView.setText(getChild(groupPosition,childPosition).toString());
return textView;
}
@Override
public Object getGroup(int groupPosition) {
return groups[groupPosition];
}
@Override
public int getGroupCount() {
return groups.length;
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
//父列表中的某一项的View
@Override
public View getGroupView(int groupPosition, booleanisExpanded,
View convertView, ViewGroup parent) {
TextView textView = getGenericView();
textView.setText(getGroup(groupPosition).toString());
return textView;
}
@Override
public boolean hasStableIds() {
return true;
}
@Override
public boolean isChildSelectable(int groupPosition, intchildPosition) {
return true;
}
//获取某一项的View
private TextView getGenericView() {
TextView textView = new TextView(_ExpandableList.this);
return textView;
}
}
可以看出,在实现可伸缩列表上,我们需要集中精神把重头戏放在这个适配器上面
- Android之可收缩展开列表ExpandableList
- Android之可收缩展开列表Expandabl…
- android-ExpandableList可展开的list
- Android 可收缩展开的 TextView
- 可展开(收缩)的列表ListView(ExpandableListView)
- jquery展开收缩列表
- Android收缩控件,展开,收缩
- Android自定义可动画展开收缩View的实现
- android 支持展开/收缩功能的列表控件
- Android支持展开/收缩功能的列表控件
- Android支持展开/收缩功能的列表控件
- Android支持展开/收缩功能的列表控件
- Android ExpandableListView列表全部展开与全部收缩
- 模拟QQ列表展开收缩
- Android 收缩展开动画
- Android 可展开列表组件 ExpandableListView
- Adapter类控件使用之ExpandableList(可折叠式列表)的基本使用
- Android展开/收缩列表 ExpandableListView 每次只能有一个项目是展开的
- Android中UI视图之试图绘制机制
- Mysql触发器详解
- 网格控件GridView在Android中的使用
- 管道技术获取控制台输出
- 为EditText输入框加上提示信息
- Android之可收缩展开列表ExpandableList
- 仍在创业的路上,些许感悟(一)
- Android中实现GPS功能基础开发实例
- linux下查看所有用户及所有用户组
- 调用一个控制台程序并取得其输出(PIPE)
- SQL语句整理【转】
- Php5 GPC绕过缺陷
- c#中调用SQLIITET部署在非开发机器中
- Javascript --Emacs