首页 > 代码库 > 使用Android-PullToRefresh实现下拉刷新功能
使用Android-PullToRefresh实现下拉刷新功能
源代码:https://github.com/chrisbanes/Android-PullToRefresh
一. 导入类库
将Library文件夹作为Android项目Import到Eclipse。
在要用的项目上右键Properties,Android一栏,Add。
二. Layout
将ListView取代为PullToRefreshListView:
<com.handmark.pulltorefresh.library.PullToRefreshListView
android:id="@+id/pull_to_refresh_listview"
android:layout_height="fill_parent"
android:layout_width="fill_parent" />
三. Activity
四. 取得内部控件
The first thing to know about this library is that it is a wrapper around the existing View classes.
So if you use this library and want to get access to the internal ListView/GridView/etc then simply call getRefreshableView(). You can then call all of your usual methods such as setOnClickListener() etc.
三. Activity
// Set a listener to be invoked when the list should be refreshed.
PullToRefreshListView pullToRefreshView = (PullToRefreshListView) findViewById(R.id.pull_to_refresh_listview);
pullToRefreshView.setOnRefreshListener(new OnRefreshListener<ListView>() {
@Override
public void onRefresh(PullToRefreshBase<ListView> refreshView) {
// Do work to refresh the list here.
new GetDataTask().execute();
}
});
private class GetDataTask extends AsyncTask<Void, Void, String[]> {
...
@Override
protected void onPostExecute(String[] result) {
// Call onRefreshComplete when the list has been refreshed.
pullToRefreshView.onRefreshComplete();
super.onPostExecute(result);
}
}
四. 取得内部控件
The first thing to know about this library is that it is a wrapper around the existing View classes.
So if you use this library and want to get access to the internal ListView/GridView/etc then simply call getRefreshableView(). You can then call all of your usual methods such as setOnClickListener() etc.
使用Android-PullToRefresh实现下拉刷新功能
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。