Android ExpandableListView的基本使用
来源:互联网 发布:linux vim 命令大全 编辑:程序博客网 时间:2024/04/30 17:22
ExpandableListView又称可折叠listView 是android中可以实现下拉list的一个控件,具体的实现方法如下:
首先:在layout的xml文件中定义一个ExpandableListView
定义两个List,用来存放控件中mlist/child中的String
获取两个集合中的数据
然后是通过适配器进行赋值
private class ExpandableAdapter extends BaseExpandableListAdapter {
private List<String> oneList;
private List<List<String>> twoList;
private GroupHolder groupHolder;
private ItemHolder itemHolder;
public ExpandableAdapter(List<String> oneList,
List<List<String>> towList) {
this.oneList = oneList;
this.twoList = towList;
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return twoList.get(groupPosition).get(childPosition);
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = getLayoutInflater().inflate(R.layout.expa_itme,
null);
itemHolder = new ItemHolder();
itemHolder.et_view = (TextView) convertView
.findViewById(R.id.et_view);
convertView.setTag(itemHolder);
} else {
itemHolder = (ItemHolder) convertView.getTag();
}
itemHolder.et_view.setText(twoList.get(groupPosition).get(
childPosition));
return convertView;
}
@Override
public int getChildrenCount(int groupPosition) {
return twoList.get(groupPosition).size();
}
@Override
public Object getGroup(int groupPosition) {
return oneList.get(groupPosition);
}
@Override
public int getGroupCount() {
return oneList.size();
}
@Override
public long getGroupId(int groupPosition) {
return 0;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = getLayoutInflater().inflate(R.layout.expa_itme,
null);
groupHolder = new GroupHolder();
groupHolder.et_view = (TextView) convertView
.findViewById(R.id.et_view);
convertView.setTag(groupHolder);
} else {
groupHolder = (GroupHolder) convertView.getTag();
}
groupHolder.et_view.setText(oneList.get(groupPosition));
return convertView;
}
@Override
public boolean hasStableIds() {
return true;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
class GroupHolder {
public TextView et_view;
}
class ItemHolder {
public TextView et_view;
}
- Android ExpandableListView的基本使用
- ExpandableListView的基本使用
- Android ExpandableListView的使用
- Android ExpandableListView的使用
- Android ExpandableListView的使用
- Android ExpandableListView的使用
- Android ExpandableListView的使用
- Android ExpandableListView的使用
- Android ExpandableListView的使用
- android-ExpandableListView的使用
- Android中ExpandableListView控件基本使用
- Android中ExpandableListView控件基本使用
- Android中ExpandableListView控件基本使用 .
- Android中ExpandableListView控件基本使用
- Android中ExpandableListView控件基本使用
- Android中ExpandableListView控件基本使用
- Android中ExpandableListView控件基本使用
- Android中ExpandableListView控件基本使用
- Leetcode Q8
- 使用dryrun直接运行github项目查看效果
- Android动画学习笔记-Android Animation
- Activity启动时的概要交互流程
- Github作为远程仓库的使用详解
- Android ExpandableListView的基本使用
- 工程中使用 JSONkit 出现'isa' is deprecated错误的解决办法
- oracle中数据类型和其占用空间
- 常用知识汇总
- AIDL导入Android Studio
- Android之ListView下拉刷新和上拉加载实现详解(含源码Demo)
- IE6下iFrame页面嵌套html空白问题解决
- Socket.io的实时竞拍系统实现
- Java开发Web Service的简介