作者:jinnee5921_866 | 来源:互联网 | 2023-09-14 04:21
1、xml布局,这里使用第三方开源控件PullToRefreshListView。..<com.handmark.pulltorefresh.library.
1、xml布局,这里使用第三方开源控件PullToRefreshListView。
.....
xmlns:ptr="http://schemas.android.com/apk/res-auto"
android:id="@+id/TaskListView"
android:layout_
android:layout_
android:background="#ffffff"
android:cacheColorHint="@android:color/transparent"
android:clipToPadding="false"
android:divider="@null"
android:paddingBottom="1dp"
android:transcriptMode="normal"
ptr:ptrMode="pullFromStart"
ptr:ptrOverScroll="false" />
.......
2、Activity代码,实现OnRefreshListener2接口。
//初始化资源
Drawable loadingDrawable = getResources().getDrawable(R.drawable.pull_to_refresh_indicator);
//textView_new_msg_tip = (TextView) curView.findViewById(R.id.tt_new_msg_tip);
taskListView = (PullToRefreshListView) curView.findViewById(R.id.TaskListView);
taskListView.getLoadingLayoutProxy().setLoadingDrawable(loadingDrawable);
taskListView.getRefreshableView().setCacheColorHint(Color.WHITE);
taskListView.getRefreshableView().setSelector(new ColorDrawable(Color.WHITE));
taskListView.getRefreshableView().setOnTouchListener(lvPTROnTouchListener);
taskAdapter = new TaskAdapter(getActivity());
//设置刷新监听器,当拉至底部或顶部时执行对应事件。
taskListView.setOnRefreshListener(this);
//设置滚动事件
taskListView.setOnScrollListener(new PauseOnScrollListener(ImageLoader.getInstance(), true, true) {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
//
}
});
taskListView.setOnItemClickListener(taskAdapter);
//下拉触发的刷新事件
@Override
public void onPullDownToRefresh(final PullToRefreshBase refreshView) {
// TODO Auto-generated method stub
// 获取消息
refreshView.postDelayed(new Runnable() {
@Override
public void run() {
ListView mlist = taskListView.getRefreshableView();
int preSum = mlist.getCount();
//这个方面是通过异步httpclient获得json格式的网络数据
taskAdapter.getTaskList();
int afterSum = mlist.getCount();
mlist.setSelection(afterSum - preSum);
refreshView.onRefreshComplete();
}
}, 200);
}
//上拉触发的刷新事件
@Override
public void onPullUpToRefresh(final PullToRefreshBase refreshView) {
// TODO Auto-generated method stub
//
}