Android常用开源项目(三十七)
来源:互联网 发布:微信数据采集软件 编辑:程序博客网 时间:2024/05/21 21:35
Android开发之使用ExpandableListView实现时间轴
1.首先看下运行效果吧
2.代码结构图
3.具体实现步骤
<1>首先定义一级实体类GroupStatusEntity.java
<2>定义二级实体类ChildStatusEntity.java
<3>定义ExpandableListView的适配器类StatusExpandAdapter.java
public class StatusExpandAdapter extends BaseExpandableListAdapter {
private LayoutInflater inflater = null;
private List<GroupStatusEntity> groupList;
/**
* 构造方法
*/
public StatusExpandAdapter(Context context,
List<GroupStatusEntity> group_list) {
this.groupList = group_list;
inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
/**
* 返回一级Item总数
*/
@Override
public int getGroupCount() {
// TODO Auto-generated method stub
return groupList.size();
}
/**
* 返回二级Item总数
*/
@Override
public int getChildrenCount(int groupPosition) {
if (groupList.get(groupPosition).getChildList() == null) {
return 0;
} else {
return groupList.get(groupPosition).getChildList().size();
}
}
/**
* 获取一级Item内容
*/
@Override
public Object getGroup(int groupPosition) {
// TODO Auto-generated method stub
return groupList.get(groupPosition);
}
/**
* 获取二级Item内容
*/
@Override
public Object getChild(int groupPosition, int childPosition) {
return groupList.get(groupPosition).getChildList().get(childPosition);
}
@Override
public long getGroupId(int groupPosition) {
// TODO Auto-generated method stub
return groupPosition;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return childPosition;
}
@Override
public boolean hasStableIds() {
// TODO Auto-generated method stub
return false;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
GroupViewHolder holder = new GroupViewHolder();
if (convertView == null) {
convertView = inflater.inflate(R.layout.group_status_item, null);
}
holder.groupName = (TextView) convertView
.findViewById(R.id.one_status_name);
holder.groupName.setText(groupList.get(groupPosition).getGroupName());
return convertView;
}
@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
ChildViewHolder viewHolder = null;
ChildStatusEntity entity = (ChildStatusEntity) getChild(groupPosition,
childPosition);
if (convertView != null) {
viewHolder = (ChildViewHolder) convertView.getTag();
} else {
viewHolder = new ChildViewHolder();
convertView = inflater.inflate(R.layout.child_status_item, null);
viewHolder.twoStatusTime = (TextView) convertView
.findViewById(R.id.two_complete_time);
}
viewHolder.twoStatusTime.setText(entity.getCompleteTime());
convertView.setTag(viewHolder);
return convertView;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return false;
}
private class GroupViewHolder {
TextView groupName;
}
private class ChildViewHolder {
public TextView twoStatusTime;
}
}
<4>下面给出资源类的文件实现
首先是一级实体类的布局文件group_status_item.xml
其次是二级实体类的布局文件child_status_item.xml
其次是实现drawable文件中的资源文件list_line.xml
- Android常用开源项目(三十七)
- Android常用开源项目
- Android常用开源项目
- Android常用开源项目
- android 常用开源项目
- Android常用开源项目
- android常用开源项目
- Android常用开源项目
- Android常用开源项目
- 常用android、ios开源项目
- android中常用的开源项目
- Android项目常用开源框架整理
- android常用的开源项目推荐
- android常用的开源项目。
- android开源项目和常用框架
- Android开源项目和常用控件
- android中常用的开源项目
- Android常用开源项目compile
- 如何将TOMCAT注册成系统服务
- ELF相关文章
- 王者荣耀的帧同步机智
- shell脚本实现字符串截取
- node.js 学习的网站推荐
- Android常用开源项目(三十七)
- Shell特殊变量:Shell $0, $#, $*, $@, $?, $$和命令行参数
- python发邮件
- Mapreduce编程二 表关联
- 模板类:函数实现(.cpp)和函数声明(.h)分开的问题
- Android app测试没有问题,导出apk却问题百出
- ajax的同步和异步
- 多播,IP_MULTICAST_TTL,IP_ADD_MEMBERSHIP,IP_MULTICAST_IF,IP_DROP_MEMBERSHIP
- Handlebars模板引擎介绍和开发指南