android_ExpandableListView 下拉列表使用
2015-05-29 10:41
471 查看
总结一下ExpandableListView的使用
ExpandableListView与ListView用法差不多,它也有自己的适配器,可以根据自己的需求继承BaseExpandableListAdapter,自己写适配器
先上效果图
和ListView用法差不多,从项目中摘的代码
[java] view
plaincopy
<span style="white-space:pre"> </span>inEditText = (EditText) findViewById(R.id.infusion_et_in);
e_lv = (ExpandableListView) findViewById(R.id.infusion_elv);
e_lv.setAdapter(new InfusionParentAdapter(getApplication()));
[java] view
plaincopy
public class InfusionParentAdapter extends BaseExpandableListAdapter {
private Context context;
private String[] generalsTypes = new String[] { "张三", "李四" };
private String[][] generals = new String[][] { { "1", "2", "3" },
{ "4", "5", "6" } };
public InfusionParentAdapter() {
}
public InfusionParentAdapter(Context context) {
this.context = context;
}
@Override
public Object getChild(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return generals[groupPosition][childPosition];
}
@Override
public long getChildId(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return childPosition;
}
@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
convertView = LayoutInflater.from(context).inflate(
R.layout.list_item_child, null);
return convertView;
}
@Override
public int getChildrenCount(int groupPosition) {
// TODO Auto-generated method stub
return generals[0].length;
}
@Override
public Object getGroup(int groupPosition) {
// TODO Auto-generated method stub
return generalsTypes[groupPosition];
}
@Override
public int getGroupCount() {
// TODO Auto-generated method stub
return generalsTypes.length;
}
@Override
public long getGroupId(int groupPosition) {
// TODO Auto-generated method stub
return groupPosition;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
convertView=LayoutInflater.from(context).inflate(R.layout.list_item_infusion_elistview, null);
return convertView;
}
@Override
public boolean hasStableIds() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return false;
}
}
其中parent表示扩展的ListView,Child表示下拉列表的内容,其余的跟ListView用法一样了
ExpandableListView与ListView用法差不多,它也有自己的适配器,可以根据自己的需求继承BaseExpandableListAdapter,自己写适配器
先上效果图
和ListView用法差不多,从项目中摘的代码
[java] view
plaincopy
<span style="white-space:pre"> </span>inEditText = (EditText) findViewById(R.id.infusion_et_in);
e_lv = (ExpandableListView) findViewById(R.id.infusion_elv);
e_lv.setAdapter(new InfusionParentAdapter(getApplication()));
[java] view
plaincopy
public class InfusionParentAdapter extends BaseExpandableListAdapter {
private Context context;
private String[] generalsTypes = new String[] { "张三", "李四" };
private String[][] generals = new String[][] { { "1", "2", "3" },
{ "4", "5", "6" } };
public InfusionParentAdapter() {
}
public InfusionParentAdapter(Context context) {
this.context = context;
}
@Override
public Object getChild(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return generals[groupPosition][childPosition];
}
@Override
public long getChildId(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return childPosition;
}
@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
convertView = LayoutInflater.from(context).inflate(
R.layout.list_item_child, null);
return convertView;
}
@Override
public int getChildrenCount(int groupPosition) {
// TODO Auto-generated method stub
return generals[0].length;
}
@Override
public Object getGroup(int groupPosition) {
// TODO Auto-generated method stub
return generalsTypes[groupPosition];
}
@Override
public int getGroupCount() {
// TODO Auto-generated method stub
return generalsTypes.length;
}
@Override
public long getGroupId(int groupPosition) {
// TODO Auto-generated method stub
return groupPosition;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
convertView=LayoutInflater.from(context).inflate(R.layout.list_item_infusion_elistview, null);
return convertView;
}
@Override
public boolean hasStableIds() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return false;
}
}
其中parent表示扩展的ListView,Child表示下拉列表的内容,其余的跟ListView用法一样了
相关文章推荐
- Android 创建的video设备
- Android NDK学习 <一> 简介
- Android Parcelable理解与使用(对象序列化)
- Android自定义控件(四)仿网易客户端上拉加载更多
- Android自定义控制(五)仿新浪微博的下拉刷新
- android studio离线更新
- Android开发常用的颜色值
- 一起学android之自定义控件显示点赞用户并通过用户名称进入该用户主页的功能 (40)
- android圆角矩形进度条
- Pro Android学习笔记(一六六):联系人API(9):Personal Profile
- Android逐帧动画,逐帧动画加载图片过多时OOM异常的解决和替代方法
- android SDK Manager 代理服务器设置
- 【Android】Home键问题
- Android ViewPager多页面滑动切换以及动画效果---换view
- Android(第三种动画)属性动画完全解析(上),初识属性动画的基本用法
- Android USB编程
- 可以运用到android项目中的一些小技巧
- Android---49---使用ServerSocket创建服务器端
- SimpleAdapter和Baseadapter填充listActivity-android学习之旅()
- SimpleAdapter和Baseadapter填充listActivity-android学习之旅()