DevStore首页 > DEV资源 > 源码下载 > 源码详情

Android使用ExpandableListview实现时间轴TimeLineDemo

 
冰点 | 2017-03-07 16:40    浏览量(960)    评论(0)    收藏(3)
功能分类:工具 支持平台:Android 运行环境:Android
开发语言:Java 开发工具:Android Studio 源码大小:682.48KB
下载源码 53 人下载

源码简介

Android使用ExpandableListview实现时间轴TimeLineDemo,博客:http://www.jianshu.com/p/1bd4513c9098

源码截图

DevStore所有源码来自用户上传分享,版权问题及牵扯到商业纠纷均与DevStore无关。

源码片段

package cn.demo.timeline.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import cn.demo.timeline.R;
import cn.demo.timeline.entity.TimeLine;
import cn.demo.timeline.fulllistview.NestFullListView;
import cn.demo.timeline.fulllistview.NestFullListViewAdapter;
import cn.demo.timeline.fulllistview.NestFullViewHolder;

/**
 * Created by Administrator on 2017/2/18.
 */

public class TimeLineAdapter extends BaseExpandableListAdapter {

    private Context context;
    private List rowsBeanList;

    public TimeLineAdapter(Context context, List rowsBeanList) {
        this.context = context;
        if (rowsBeanList == null){
            this.rowsBeanList = new ArrayList<>();
        }else {
            this.rowsBeanList = rowsBeanList;
        }
    }

    @Override
    public int getGroupCount() {
        return rowsBeanList.size();
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return rowsBeanList.get(groupPosition).getDaylist().size();
    }

    @Override
    public TimeLine.RowsBean getGroup(int groupPosition) {
        return rowsBeanList.get(groupPosition);
    }

    @Override
    public TimeLine.RowsBean.DaylistBean getChild(int groupPosition, int childPosition) {
        return rowsBeanList.get(groupPosition).getDaylist().get(childPosition);
    }

    @Override
    public long getGroupId(int groupPosition) {
        return groupPosition;
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return childPosition;
    }

    @Override
    public boolean hasStableIds() {
        return true;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
        GroupHolder groupHolder = null;
        if (convertView == null){
            groupHolder = new GroupHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_group_timeline,null);
            groupHolder.itemGroupTopLine = convertView.findViewById(R.id.item_group_top_line);
            groupHolder.itemGroupYearMonth = (TextView) convertView.findViewById(R.id.item_group_year_month);
            convertView.setTag(groupHolder);
        }else {
            groupHolder = (GroupHolder) convertView.getTag();
        }
        if (groupPosition == 0){
            groupHolder.itemGroupTopLine.setVisibility(View.INVISIBLE);
        }else {
            groupHolder.itemGroupTopLine.setVisibility(View.VISIBLE);
        }
        TimeLine.RowsBean rowsBean = getGroup(groupPosition);
        if (null != rowsBean){
            groupHolder.itemGroupYearMonth.setText(rowsBean.getMonth() +"月" + "\n" + rowsBean.getYear());
        }
        return convertView;
    }

    class GroupHolder {
        View itemGroupTopLine;
        TextView itemGroupYearMonth;
        View itemGroupBottomLine;

    }

    @Override
    public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
        ChildHolder childHolder = null;
        if (convertView == null){
            childHolder = new ChildHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_child_timeline,null);
            childHolder.itemChildMonthDay = (TextView) convertView.findViewById(R.id.item_child_month_day);
            childHolder.itemChildLv = (NestFullListView) convertView.findViewById(R.id.item_child_lv);
            convertView.setTag(childHolder);
        }else {
            childHolder = (ChildHolder) convertView.getTag();
        }
        TimeLine.RowsBean.DaylistBean daylistBean = getChild(groupPosition, childPosition);
        if (null != daylistBean){
            childHolder.itemChildMonthDay.setText(daylistBean.getMonth() + "月" + daylistBean.getDay() + "日");
            childHolder.itemChildLv.setAdapter(new NestFullListViewAdapter(R.layout.item_child_timeline_data,daylistBean.getDatalist()) {
                @Override
                public void onBind(int pos, TimeLine.RowsBean.DaylistBean.DatalistBean datalistBean, NestFullViewHolder holder) {
                    holder.setText(R.id.item_child_sr_name,datalistBean.getName());
                    holder.setText(R.id.item_child_sr_progress,datalistBean.getProgress() + "%");
                }
            });
        }

        return convertView;
    }

    class ChildHolder{
        TextView itemChildMonthDay;
        NestFullListView itemChildLv;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return false;
    }

    public void add(List rowsBeanList){
        if (null != rowsBeanList && rowsBeanList.size() != 0){
            this.rowsBeanList.addAll(rowsBeanList);
            notifyDataSetChanged();
        }
    }
}
  •   赞(0) 赞 +1 赞(0) 已赞
  •   收藏(3) 收藏 +1 已收藏 取消
  •   下载(53)
评论(0)
  • 推荐
  • 审核
  • 收录
  • 获取活力值

源码上传作者

  • 20 能力值
  • 11 源码
  • 0 评测
  • 0 资料