listview实现时间轴显示效果

来源:互联网 发布:游戏编程需要怎么学 编辑:程序博客网 时间:2024/06/07 06:49

****************************************************************************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

原创粉丝点击