ListView 实现像Android Market那样 分页加载 滚动加载(2)
来源:未知 责任编辑:责任编辑 发表时间:2013-11-17 14:37 点击:次
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
// TODO Auto-generated method stub
Log.i("test" , "Scroll>>>first: " + firstVisibleItem + ", visible: " + visibleItemCount + ", total: " + totalItemCount);
lastItem = firstVisibleItem + visibleItemCount - 1;
Log.i("test" , "Scroll>>>lastItem:" + lastItem);
//显示50条ListItem,即0-49,因为onScroll是在“滑动”执行过之后才触发,所以用adapter.count<=41作条件
int scrolllength=101;
if (adapter.count<=scrolllength) {
if (firstVisibleItem+visibleItemCount==totalItemCount) {
adapter.count += 10;
adapter.notifyDataSetChanged();
listView.setSelection(lastItem);
int currentPage=adapter.count/10;
Toast.makeText(getApplicationContext(), "第"+currentPage+"页", Toast.LENGTH_LONG).show();
}
}
else {
listView.removeFooterView(loadingLayout);
}
}
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
// TODO Auto-generated method stub
}
});
}
class listViewAdapter extends BaseAdapter {
int count = 10; /* starting amount */
public int getCount() {
return count;
}
public Object getItem(int pos) {
return pos;
}
public long getItemId(int pos) {
return pos;
}
public View getView(int pos, View v, ViewGroup p) {
Log.i("test", "getView>>>pos:" + pos);
TextView view;
if (v == null) {
view = new TextView(ListViewScroll.this);
} else {
view = (TextView) v;
}
view.setText("ListItem " + pos);
view.setTextSize(20f);
view.setGravity(Gravity.CENTER);
view.setHeight(60);
return view;
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 进入详细评论页>>