/**
* 给listView添加滚动事件监听
*/
listView.setOnScrollListener(new OnScrollListener() {
//是否到底了 设置为false
boolean atBottom=false;
/**
* 滚动状态改变时执行
*/
public void onScrollStateChanged(AbsListView view, int scrollState) {
switch (scrollState) {
case OnScrollListener.SCROLL_STATE_IDLE:
Log.i("info", "空闲状态..");
//到底了 加载后续数据
if(atBottom){
model.loadNewMusicList(songs.size(), 20, new Callback(){
public void onMusicListLoaded(List<Song> songs) {
if(songs!=null){
NewMusicListFragment.this.songs.addAll(songs);
adapter.notifyDataSetChanged();
}else{
Toast.makeText(getActivity(), "没有了!", Toast.LENGTH_SHORT).show();
}
}
});
}
break;
case OnScrollListener.SCROLL_STATE_TOUCH_SCROLL:
Log.i("info", "摁住滚的状态..");
break;
case OnScrollListener.SCROLL_STATE_FLING:
Log.i("info", "飞的状态..");
break;
}
}
/**
*当滚动的时候
/
public void onScroll(AbsListView view,
int firstVisibleItem, //屏幕中第一个可见item的下标
int visibleItemCount, //可见item的数量
int totalItemCount //item的总数量
) {
if(totalItemCount!=0 && firstVisibleItem+visibleItemCount==totalItemCount){
Log.i("info", "到底了...."+totalItemCount);
//说明到底了
atBottom=true;
}else{
//没有到底
atBottom=false;
}
}
});