标签:
说到ListView下拉刷新几乎每个APP都会用到,所以ListView下拉刷新是很重要的,就像ListView优化一样是你必会的东西。
<!--The PullToRefreshListView replaces a standard ListView widget. The ID CAN NOT be @+id/android:list--> <com.handmark.pulltorefresh.library.PullToRefreshListView android:id="@+id/pull_to_refresh_listview" android:layout_height="fill_paren"
android:layout_width="fill_parent" />
PullToRefreshListView mPullToRefreshListView = (PullToRefreshListView)findViewById(R.id.pull_to_refresh_listview);
4.2.设置一个监听器,被调用时刷新列表(下拉刷新)
mPullToRefreshListView.setOnRefreshListener(new OnRefreshListener<ListView>() { @Override public void onRefresh( PullToRefreshBase<ListView> refreshView) { String label = DateUtils.formatDateTime( getApplicationContext(), System.currentTimeMillis(), DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_ALL); // 更新最后更新标签 refreshView.getLoadingLayoutProxy() .setLastUpdatedLabel(label); if (refreshView.getCurrentMode() == Mode.PULL_FROM_END) { // 在这里做刷新的工作(加载更多) new GetDataTask(false).execute(); } else { // 在这里做刷新的工作(下拉刷新) new GetDataTask(true).execute(); } } });
4.3.添加列表底部监听器(滑动到ListView底部时回调):
mPullToRefreshListView.setOnLastItemVisibleListener(new OnLastItemVisibleListener() { @Override public void onLastItemVisible() { Toast.makeText(MainActivity.this, "End of List!", Toast.LENGTH_SHORT).show(); } });
4.4.添加声音事件监听:
SoundPullEventListener<ListView> soundListener = new SoundPullEventListener<ListView>(this); soundListener.addSoundEvent(State.PULL_TO_REFRESH, R.raw.pull_event); // 下拉刷新声音事件 soundListener.addSoundEvent(State.REFRESHING, R.raw.refreshing_sound); // 刷新声音事件 soundListener.addSoundEvent(State.RESET, R.raw.reset_sound); // 重置声音事件,刷新完成之后 // State.MANUAL_REFRESHING 手动刷新状态 mPullToRefreshListView.setOnPullEventListener(soundListener);//添加事件监听
标签:
原文地址:http://www.cnblogs.com/williamguan/p/4584105.html