本文记述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)