Android——ListView上拉刷新与下拉刷新

本文记述ListView的上拉与下拉的刷新数据

首先需要自定义一个MyListView,继承于ListView

public class MyListView extends ListView implements AbsListView.OnScrollListener {
   

    private View bottomview; //尾文件
    private View headview; //头文件
    private int totaItemCounts;//用于表示是下拉还是上拉
    private int lassVisible; //上拉
    private int firstVisible; //下拉
    private LoadListener loadListener; //接口回调
    private int bottomHeight;//尾文件高度
    private int headHeight; //头文件高度
    private int Yload;//位置
    boolean isLoading;//加载状态
    private TextView headtxt;//头文件textview显示加载文字
    private TextView headtime;//头文件textview显示加载时间
    private ProgressBar progressBar;//加载进度

    public MyListView(Context context) {
   
        super(context);
        Init(context);
    }

    public MyListView(Context context, AttributeSet attrs) {
   
        super(context, attrs);
        Init(context);
    }

    public MyListView(Context context, AttributeSet attrs, int defStyleAttr) {
   
        super(context, attrs, defStyleAttr);
        Init(context);
    }

    private void Init(Context context) {
   
        //拿到头布局文件xml
        headview= LinearLayout.inflate(context, R.layout.head, null);
        headtxt=(TextView) headview.findViewById(R.id.headtxt);
        headtime=(TextView) headview.findViewById(R.id.timetxt);
        progressBar=(ProgressBar) headview.findViewById(R.id.headprogress);
        headtime.setText("上次更新时间:"+ new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(System.currentTimeMillis()));

        //拿到尾布局文件
        bottomview=LinearLayout.inflate(context, R.layout.bottom, null);
        //测量尾文件高度
        bottomview.measure(0,0);
        //拿到高度
        bottomHeight=bottomview.getMeasuredHeight();
        //隐藏view
        bottomview.setPadding(0, -bottomHeight, 0, 0)
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值