listview实现时间轴显示效果

****************************************************************************8不喜勿喷,有问题互相交流,谢谢**********************8

上代码,主界面

public class MainActivity extends AppCompatActivity {
   private ArrayList<TimeLineContent> dataList;

   /**
    * 显示物流的listview
    * */
   private ListView lv_TimeLine;


   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.timeline);
      lv_TimeLine=(ListView) findViewById(R.id.list_TimeLine);

      //可以通过网络获取数据传入
      dataList = new ArrayList<TimeLineContent>();
      dataList.add(new TimeLineContent("","2017-07-01","广州","1"));
      dataList.add(new TimeLineContent("","2017-07-02","福田区","1"));
      dataList.add(new TimeLineContent("","2017-07-03","南山区","0"));
      dataList.add(new TimeLineContent("","2017-07-04","宝安区","0"));
      dataList.add(new TimeLineContent("","2017-07-05","待收货","0"));

      lv_TimeLine.setAdapter(new TimeLineAdapter(dataList,this));
   }

}
==========================================================================================================================

/**
 * 时间轴内容
 */
public class TimeLineContent {
    private String name;//预留
    private String timeStr;
    private String addressStr;
    private String zt;

    public TimeLineContent(String name, String timeStr, String addressStr, String zt) {
        this.name = name;
        this.timeStr = timeStr;
        this.addressStr = addressStr;
        this.zt = zt;
    }

    public String getZt() {
        return zt;
    }

    public void setZt(String zt) {
        this.zt = zt;
    }

    public String getAddressStr() {
        return addressStr;
    }

    public void setAddressStr(String addressStr) {
        this.addressStr = addressStr;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getTimeStr() {
        return timeStr;
    }

    public void setTimeStr(String timeStr) {
        this.timeStr = timeStr;
    }
}
=================================================================================================================================

* 动态适配
 */
public class TimeLineAdapter extends BaseAdapter{
    private ArrayList<TimeLineContent>  dataList;
    private Context context;

    public TimeLineAdapter(ArrayList<TimeLineContent> timeLineList,Context context){
        this.context = context;
        this.dataList = timeLineList;
    }
    @Override
    public int getCount() {
        return dataList.size();
    }

    @Override
    public Object getItem(int position) {
        return dataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
        TimeLineViewHold viewHold;
        if(null == view ){
            view = View.inflate(context,R.layout.timeline_itme,null);
            viewHold = new TimeLineViewHold();
            viewHold.time = (TextView) view.findViewById(R.id.time);
            viewHold.address = (TextView) view.findViewById(R.id.address);
            viewHold.zhuangtai = (TextView) view.findViewById(R.id.zhuangtai);
            viewHold.timeLineTextColor = (TextView) view.findViewById(R.id.timeLineTextColor);
            viewHold.timeLineTextColor_TOP = (TextView) view.findViewById(R.id.timeLineTextColor_TOP);
            viewHold.imageView_Bottom = (ImageView) view.findViewById(R.id.imageView_Bottom);
            viewHold.imageView_Bottom_yd= (ImageView) view.findViewById(R.id.imageView_Bottom_yd);
            view.setTag(viewHold);
        }else {
            viewHold =(TimeLineViewHold) view.getTag();
        }
        viewHold.time.setText(dataList.get(position).getTimeStr());
        viewHold.address.setText(dataList.get(position).getAddressStr());

        String zt = dataList.get(position).getZt();
        if(null!=zt&&zt.equals("1")){
            viewHold.zhuangtai.setText("已完成");
            viewHold.zhuangtai.setTextColor(context.getResources().getColor(R.color.color_ff7300));
            viewHold.timeLineTextColor.setBackgroundColor(context.getResources().getColor(R.color.color_ff7300));
            viewHold.timeLineTextColor_TOP.setBackgroundColor(context.getResources().getColor(R.color.color_ff7300));
            viewHold.address.setTextColor(context.getResources().getColor(R.color.color_ff7300));
        }else{
            viewHold.zhuangtai.setTextColor(context.getResources().getColor(R.color.color_A3A3A3));
            viewHold.timeLineTextColor_TOP.setBackgroundColor(context.getResources().getColor(R.color.color_A3A3A3));
            viewHold.timeLineTextColor.setBackgroundColor(context.getResources().getColor(R.color.color_A3A3A3));
            viewHold.address.setTextColor(context.getResources().getColor(R.color.color_A3A3A3));
            viewHold.zhuangtai.setText("未完成");
        }

        if(position == dataList.size()-1){
            viewHold.imageView_Bottom_yd.setVisibility(View.GONE);
            viewHold.imageView_Bottom.setVisibility(View.VISIBLE);
        }else{
            viewHold.imageView_Bottom_yd.setVisibility(View.VISIBLE);
            viewHold.imageView_Bottom.setVisibility(View.GONE);
        }
        return view;
    }

    private class TimeLineViewHold{
        private TextView time;
        private TextView address;
        private TextView zhuangtai;
        private TextView timeLineTextColor;
        private TextView timeLineTextColor_TOP;
        private ImageView imageView_Bottom,imageView_Bottom_yd;

    }
}
=================================================================================================================================

demo地址:

链接:http://pan.baidu.com/s/1c2hDXlA 密码:nx6a

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值