android下拉刷新控件之第三方开源控件的使用实现
来源:互联网 发布:数据统计网站模板 编辑:程序博客网 时间:2024/06/01 15:18
本次使用的第三方下拉刷新控件是:Android-Pull-Refresh,下载地址:https://github.com/chrisbanes/Android-PullToRefresh
该控件适用于:
- ViewPager
- HorizontalScrollView
- ScrollView
- WebView
- GridView
- ListView
- ExpandableListView
- ListFragment
从github上下载解压后,将library,PullToRefreshListFragment,PullToRefreshViewPager导入项目后,右键自己新建的项目,选择Properties,进入如下图的页面后点击Add添加即可:
添加好后即可开始编写Demo,具体代码如下:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <!-- The PullToRefreshListView replaces a standard ListView widget. --> <com.handmark.pulltorefresh.library.PullToRefreshListView xmlns:ptr="http://schemas.android.com/apk/res-auto" android:id="@+id/pull_refresh_list" android:layout_width="fill_parent" android:layout_height="fill_parent" android:cacheColorHint="#00000000" android:divider="#19000000" android:dividerHeight="4dp" android:fadingEdge="none" android:fastScrollEnabled="false" android:footerDividersEnabled="false" android:headerDividersEnabled="false" android:smoothScrollbar="true" ptr:ptrDrawable="@drawable/ic_launcher" ptr:ptrMode="both" /></LinearLayout>
import java.util.ArrayList;import java.util.List;import android.app.Activity;import android.os.AsyncTask;import android.os.Bundle;import android.widget.ArrayAdapter;import android.widget.ListView;import android.widget.Toast;import com.handmark.pulltorefresh.library.PullToRefreshBase;import com.handmark.pulltorefresh.library.PullToRefreshBase.OnLastItemVisibleListener;import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener;import com.handmark.pulltorefresh.library.PullToRefreshListView;/** * MainActivity---利用第三方下拉刷新控件实现 * @author seabear * */public class MainActivity extends Activity {private PullToRefreshListView mPullToRefreshListView;private List<String> mArrayList = new ArrayList<String>();private ArrayAdapter<String> mArrayAdapter;private int mNums = 0;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);mPullToRefreshListView = (PullToRefreshListView)this.findViewById(R.id.pull_refresh_list);mArrayAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, mArrayList);mPullToRefreshListView.setAdapter(mArrayAdapter);mPullToRefreshListView.setOnRefreshListener(new OnRefreshListener<ListView>() {@Overridepublic void onRefresh(PullToRefreshBase<ListView> refreshView) {// TODO Auto-generated method stubnew GetDataTask().execute();}});}private class GetDataTask extends AsyncTask<Void, Void, String>{@Overrideprotected String doInBackground(Void... params) {// Simulates a background job.mNums++;try {Thread.sleep(2000);} catch (InterruptedException e) {}return "第" + String.valueOf(mNums) + "行";}@Overrideprotected void onPostExecute(String result) {mArrayList.add(result);mArrayAdapter.notifyDataSetChanged();// Call onRefreshComplete when the list has been refreshed.mPullToRefreshListView.onRefreshComplete();super.onPostExecute(result);}}}
1 1
- android下拉刷新控件之第三方开源控件的使用实现
- Android高级控件系列二之第三方控件PullToRefreshListView下拉刷新的使用
- Android高级控件系列三之第三方控件XListView下拉刷新实现代码
- Android自定义控件--下拉刷新的实现
- Android 下拉刷新控件的使用
- Android 下拉刷新控件SwipeRefreshLayout 的使用
- Android 下拉刷新控件的使用
- ListView下拉刷新【第三方控件实现】
- 下拉刷新控件---使用第三方提供的源码
- Android 下拉刷新控件之ScrollView版本实现
- Android 下拉刷新控件之ScrollView版本实现
- Android 下拉刷新控件之ScrollView版本实现 .
- android 下拉刷新控件
- Android 下拉刷新控件
- Android下拉刷新控件
- Android 类ListView下拉刷新控件实现
- Android 类ListView下拉刷新控件实现 .
- Android 类ListView下拉刷新控件实现
- 全选,不选,输出选中的值
- 【Android】Android之搭建开发环境(eclipse)
- 设计模式原则总结
- GRE写作必备句型
- C++程序编译过程简介
- android下拉刷新控件之第三方开源控件的使用实现
- SUID,SGID,Sticky Bit详解
- Ubuntu14.04安装运行bochs
- 2012年5月SAT香港真题解析
- JAVA中的WeakReference(弱引用)
- 收藏网站77
- Java读写Windows共享文件夹
- 自定义SpringMVC配置文件名称以及路径
- 收藏网站78