首先介绍一下 SwipeRefreshLayout ,由于下拉刷新使用的人比较多,于是谷歌自己就做了一个下拉刷新的控件.

android.support.v4.widget.SwipeRefreshLayout

具体是使用方法:

//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.swiperefresh.MainActivity" > <android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/srl"
android:layout_width="match_parent"
android:layout_height="match_parent" > <ListView
android:id="@+id/lv"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</android.support.v4.widget.SwipeRefreshLayout> </LinearLayout>
//Activity
package com.example.swiperefresh; import java.util.ArrayList; import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener;
import android.widget.ArrayAdapter;
import android.widget.ListView; public class MainActivity extends Activity { private ListView lv;
private SwipeRefreshLayout srl;
private ArrayAdapter<String> adapter;
private ArrayList<String> date;
private int count = 0; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
date = new ArrayList<String>();
initUI(); } private void initUI() {
lv = (ListView) findViewById(R.id.lv);
srl = (SwipeRefreshLayout) findViewById(R.id.srl);
srl.setColorSchemeResources(android.R.color.holo_blue_light, android.R.color.holo_red_light, android.R.color.holo_orange_light, android.R.color.holo_green_light);
srl.setOnRefreshListener(new OnRefreshListener() { @SuppressWarnings("unchecked")
@Override
public void onRefresh() {
new listAsyncTask().execute();
}
});
adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1,
date);
lv.setAdapter(adapter);
} public class listAsyncTask extends AsyncTask { @Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
srl.setRefreshing(true);
} @Override
protected Object doInBackground(Object... params) {
// TODO Auto-generated method stub
return count++;
} @Override
protected void onPostExecute(Object result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
date.add(0, "" + result);
adapter.notifyDataSetChanged();
srl.setRefreshing(false);
}
} }

Android SwipeRefreshLayout的更多相关文章

  1. Xamarin android SwipeRefreshLayout入门实例

    android SwipeRefreshLayout 是实现的效果就是上滑下拉刷新ListView 获取其他控件数据.基本上每个App都有这种效果.Google提供了一个官方的刷新控件SwipeRef ...

  2. Android SwipeRefreshLayout 下拉刷新——Hi_博客 Android App 开发笔记

    以前写下拉刷新 感觉好费劲,要判断ListView是否滚到顶部,还要加载头布局,还要控制 头布局的状态,等等一大堆.感觉麻烦死了.今天学习了SwipeRefreshLayout 的用法,来分享一下,有 ...

  3. android SwipeRefreshLayout google官方下拉刷新控件

    下拉刷新功能之前一直使用的是XlistView很方便我前面的博客有介绍 SwipeRefreshLayout是google官方推出的下拉刷新控件使用方法也比较简单 今天就来使用下SwipeRefres ...

  4. Android --SwipeRefreshLayout 下拉刷新

    1.Layout <android.support.v4.widget.SwipeRefreshLayout android:id="@+id/id_swipe_ly" an ...

  5. Android SwipeRefreshLayout 官方下拉刷新控件介绍

    转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/24521483 下面App基本都有下拉刷新的功能,以前基本都使用XListView ...

  6. 使用Android SwipeRefreshLayout了解Android的嵌套滑动机制

    SwipeRefreshLayout 是在Android Support Library, revision 19.1.0加入到support v4库中的一个下拉刷新控件,关于android的下拉刷新 ...

  7. 解决android SwipeRefreshLayout recyclerview 不能下拉

    http://stackoverflow.com/questions/25178329/recyclerview-and-swiperefreshlayout 23down vote write th ...

  8. Android原生下拉刷新SwipeRefreshLayout实践

    本篇文章翻译自Ravi Tamada的Android Swipe Down to Refresh ListView Tutorial 首先来看一下效果图 你应该发现很多的android app比如Tw ...

  9. Android 下拉刷新

    以前旧版用的是开源的PullToRefresh第三方库,该库现在已经不再维护了: chrisbanes/Android-PullToRefreshhttps://github.com/chrisban ...

随机推荐

  1. Flash Recovery Area空间不足导致DB不能打开或hang住处理方法

    当归档目录设置在闪回恢复区,并且闪回恢复区又满了的情况下, DB 就会无法归档而hang住或者无法打开. 这种情况下打开数据库会遇到如下错误信息: SQL> select status from ...

  2. C# in Depth阅读笔记1:C#1特性

    1.委托 委托是对包含返回值和参数的行为的一种封装,类似于单一方法的接口. 委托是不易变的(就像string),system.delegate下的combine和remove方法都只能产生一个新的委托 ...

  3. Tomcat无法安装 Check your settings and permissions Ignore and continue anyway

    刚刚“sj”,把装在C盘的tomcat的文件夹给删除了,刚删完就想到干嘛不卸载啊,哎惯性思维啊,转而一想,tomcat这么简单安装,不怕不怕,后来一装,妈啊,装不了,百度之后原来是服务没有删除,好吧, ...

  4. web.config configSections自定义section

    1.web.config 配置文件设置 <configSections> <!-- For more information on Entity Framework configur ...

  5. JS删除练习

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...

  6. LevelDB.NET性能测试

    最近了解了一下LevelDB,发觉这个嵌入式的K-V数据性能不错,所以顺便想在使用层面了解一下.由于LevelDB也有针对.net的实现,所以就针对了LevelDB.NET进行了一个简单的读写压力测试 ...

  7. String.Empty、string=”” 和null的区别

    String.Empty是string类的一个静态常量: String.Empty和string=””区别不大,因为String.Empty的内部实现是: 1 2 3 4 5 6 7 8 9 10 1 ...

  8. C语言静态函数静态变量

    C语言程序可以看成由一系列外部对象构成,这些外部对象可能是变量或函数.而内部对象是指定义在函数内部的函数参数及变量. 外部变量定义在函数之外,因此可以在许多函数中使用.由于C语言不允许在一个函数中定义 ...

  9. Gradle templates 的使用

    使用gradle 时有一些繁琐的创建工程 使用插件的步骤. 这些步骤可以使用一些gradle的模板来代替. 具体的操作步骤: 安装gradle: Prerequired: Java SDK insta ...

  10. Oracle EBS-SQL (PO-8):检查有供货比例无采购员.sql

    select distinct msr.sourcing_rule_name            名称 , msi.description                          说明 , ...