ListView 滚动翻页/滚动加载(类似Android Market的列表)
1.滚动加载
listView.setOnScrollListener(new OnScrollListener() { //添加滚动条滚到最底部,加载余下的元素 @Override public void onScrollStateChanged(AbsListView view, int scrollState) { if (scrollState == OnScrollListener.SCROLL_STATE_IDLE) { loadRemnantListItem(); } } @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {} }); listView.setOnItemSelectedListener(new OnItemSelectedListener() { //按键选择List中的item,焦点落在最下面的view上加载余下的item @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if(footerView == view) { loadRemnantListItem(); listView.setSelection(position - 1); } } @Override public void onNothingSelected(AdapterView<?> parent) {} }); private void loadRemnantListItem() {//滚到加载余下的数据 //动态的改变listAdapter.getCount()的返回值 //使用Handler调用listAdapter.notifyDataSetChanged();更新数据 }
2.滚动翻页
//listView监听器代码相同 private void loadRemnantListItem() {//滚到加载余下的数据 //重新listView.setAdapter(newsAdapter); //使用Handler调用listAdapter.notifyDataSetChanged();更新数据 }