分类: Android平台
2014-11-23 23:37:49
1、 新建加载更多提示布局文件footer_layout.xml
2、 LoadListVeiw extends ListView,构造时加载footer_layout提示布局到listview,提示隐藏GONE。
LayoutInflater inflater = LayoutInflater.from(context);
footer = inflater.inflate(R.layout.footer_layout, null);
footer.findViewById(R.id.load_layout).setVisibility(View.GONE);
this.addFooterView(footer);
3、 LoadListVeiw实现OnScrollListene接口,监听loadlistview滑动到最底端时,显示提示布局VISIBLE,加载数据。完成时通知listview加载完毕,隐藏GONE
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
// TODO Auto-generated method stub
this.lastVisibleItem = firstVisibleItem + visibleItemCount;
this.totalItemCount = totalItemCount;
}
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
// TODO Auto-generated method stub
if (totalItemCount == lastVisibleItem
&& scrollState == SCROLL_STATE_IDLE) {
if (!isLoading) {
isLoading = true;
footer.findViewById(R.id.load_layout).setVisibility(
View.VISIBLE);
// 加载更多
iLoadListener.onLoad();
}
}
}
4、 通过接口回调方法,让listview通知MainActivity加载显示。listview定义接口,
public void setInterface(ILoadListener iLoadListener){
this.iLoadListener = iLoadListener;
}
//加载更多数据的回调接口
public interface ILoadListener{
public void onLoad();
}
MainActivity设置回调listview.setInterface(this),实现接口:
public void onLoad() {
//获取更多数据
getLoadData();
//更新listview显示;
showListView(info_list);
//通知listview加载完毕
listview.loadComplete();
}