Android下拉刷新库使用
来源:互联网 发布:nginx反向代理好处 编辑:程序博客网 时间:2024/06/05 01:51
Android下拉刷新库使用
本文主要介绍第三方下拉刷新库PullToRefresh使用,关于这个下拉刷新库的使用介绍文章很多,本文主要针对初学者并Android开发工具eclipse做一些简单使用介绍。
相信有很多同学下载这个资源很跑不起来,这是因为你要到依赖库包括PullToRefresh和Android兼容v7库这两个看才能正常使用,至于v7库后期我会说明作用是什么。
依赖库导入
下图是导入的库:
有同学一定不会导入,好吧我也简单介绍一下,图文教程我就直接上了,
首先邮件选择import,如图:
接下来选择Android点击Existing…..这个选项
然后点击 Browse…找到依赖库的位置导入即可
记住这里依赖库位置和项目位置要保持一致不然会报错,导入完成可以看到四个文件,下拉刷新库中包括一个demo文件,下图第一个红框就是demo,可以直接运行使用
使用下拉刷新库
一共两个地方,第一个是xml文件,
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.pulltoscollview.MainActivity" > PullToRefreshListView这个可以换成PullToRefreshGridView,PullToRefreshHorizontalScrollView等都可以 <com.handmark.pulltorefresh.library.PullToRefreshListView android:id="@+id/listView" android:layout_width="match_parent" android:layout_height="match_parent" > </com.handmark.pulltorefresh.library.PullToRefreshListView></LinearLayout>
下面是java文件,
import java.util.ArrayList;import java.util.List;import com.handmark.pulltorefresh.library.PullToRefreshBase;import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener;import com.handmark.pulltorefresh.library.PullToRefreshListView;import android.annotation.SuppressLint;import android.app.Activity;import android.os.AsyncTask;import android.os.Bundle;import android.widget.ArrayAdapter;import android.widget.ListView;public class MainActivity extends Activity { //PullToRefreshListView 这个和xml文件中<com.handmark.pulltorefresh.library.PullToRefreshListView中的PullToRefreshListView保持一直,下面有PullToRefreshListView就要和xml文件保持一致 PullToRefreshListView lv; ArrayAdapter<String>adapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); lv=(PullToRefreshListView) findViewById(R.id.listView); List<String>arr=new ArrayList<String>(); arr.add("sas"); arr.add("ds"); adapter=new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,arr); lv.setAdapter(adapter); lv.setOnRefreshListener(new OnRefreshListener<ListView>() { @Override public void onRefresh(PullToRefreshBase<ListView> refreshView) { // TODO Auto-generated method stub new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... arg0) { // TODO Auto-generated method stub try { Thread.sleep(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } @SuppressLint("NewApi") @Override protected void onPostExecute(Void result) { // TODO Auto-generated method stub super.onPostExecute(result); adapter.addAll("dsd","dsd"); lv.onRefreshComplete(); }; }.execute(); } }); }}
最后加上demo地址Android下拉刷新库使用
阅读全文
0 0
- Android下拉刷新库使用
- android 下拉刷新使用
- Android-下拉刷新库
- android使用SwipeRefreshLayout下拉刷新
- 下拉刷新库android-Ultra-Pull-To-Refresh的使用
- Android 特效库 - 下拉刷新
- Android 下拉刷新库(最新)
- Android 下拉刷新控件的使用
- Android下拉刷新框架PullToRefresh使用小结
- Android 下拉刷新控件SwipeRefreshLayout 的使用
- Android 下拉刷新控件的使用
- 【Android】使用 SwipeRefreshLayout 实现下拉刷新
- Android SwipeRefreshLayout 下拉刷新组件的使用
- android使用PulltoRefushGridview实现下拉刷新
- Android SwipeRefreshLayout 官方下拉刷新控件使用
- android 下拉刷新控件SwipeRefreshLayout简单使用
- Android万能下拉刷新控件SwipeRefleshLayout使用
- 【Android】Webview 如何使用SwipeRefreshLayout下拉刷新
- web前端性能优化总结
- Java静态方法为什么不能访问非静态方法
- 蓝牙HCI剖析(一)
- 联系我们
- ExtJS加载不到JSON数据的问题(转义字符)
- Android下拉刷新库使用
- 理解maven的核心概念
- Codeforces475D-CGCDSSQ
- jsp页面中EL表达式原样输出问题
- HEVC学习(五) —— 帧内预测系列之三
- [Lucas+数位DP] 2015 计蒜之道 复赛 C. 360的产品试用体验
- codevs2596售货员难题——状态压缩dp
- 从零开始学习OpenCL开发(一)架构
- java核心技术卷 之捕获异常