Android SwipeRefreshLayout
首先介绍一下 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的更多相关文章
- Xamarin android SwipeRefreshLayout入门实例
android SwipeRefreshLayout 是实现的效果就是上滑下拉刷新ListView 获取其他控件数据.基本上每个App都有这种效果.Google提供了一个官方的刷新控件SwipeRef ...
- Android SwipeRefreshLayout 下拉刷新——Hi_博客 Android App 开发笔记
以前写下拉刷新 感觉好费劲,要判断ListView是否滚到顶部,还要加载头布局,还要控制 头布局的状态,等等一大堆.感觉麻烦死了.今天学习了SwipeRefreshLayout 的用法,来分享一下,有 ...
- android SwipeRefreshLayout google官方下拉刷新控件
下拉刷新功能之前一直使用的是XlistView很方便我前面的博客有介绍 SwipeRefreshLayout是google官方推出的下拉刷新控件使用方法也比较简单 今天就来使用下SwipeRefres ...
- Android --SwipeRefreshLayout 下拉刷新
1.Layout <android.support.v4.widget.SwipeRefreshLayout android:id="@+id/id_swipe_ly" an ...
- Android SwipeRefreshLayout 官方下拉刷新控件介绍
转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/24521483 下面App基本都有下拉刷新的功能,以前基本都使用XListView ...
- 使用Android SwipeRefreshLayout了解Android的嵌套滑动机制
SwipeRefreshLayout 是在Android Support Library, revision 19.1.0加入到support v4库中的一个下拉刷新控件,关于android的下拉刷新 ...
- 解决android SwipeRefreshLayout recyclerview 不能下拉
http://stackoverflow.com/questions/25178329/recyclerview-and-swiperefreshlayout 23down vote write th ...
- Android原生下拉刷新SwipeRefreshLayout实践
本篇文章翻译自Ravi Tamada的Android Swipe Down to Refresh ListView Tutorial 首先来看一下效果图 你应该发现很多的android app比如Tw ...
- Android 下拉刷新
以前旧版用的是开源的PullToRefresh第三方库,该库现在已经不再维护了: chrisbanes/Android-PullToRefreshhttps://github.com/chrisban ...
随机推荐
- mma ctf 1st && csaw 2015
(很久以前做的,现在发一下)最近做了两个CTF,水平太渣,做了没几道题,挑几个自己做的记录一下. mma ctf 1st 之 rps: from socket import * s = socket( ...
- Tsinghua dsa mooc pa1
第一题Range 关键:二分查找,查找不大于一个数的最大下标. #include <cstdlib> #include <cstdio> 4 int compare (cons ...
- 【floyed】【HDU1217】【Arbitrage】
题目大意: 给你几种货币,以及几种汇率关系,问是否存在套利的可能? 思路: 初步想法:图上存在一个环的路径上权值相乘大于1.... 再者:该如何找到图上所有环呢.... 好吧 经过鸟神 和 况神的指点 ...
- Cassandra监控 - OpsCenter手册
注:本文转自:http://eric100.blog.51cto.com/2535573/1717792 Opscenter用户手册 1. OpsCenter简介 DataStaxOpsC ...
- UIButton 文档翻译(持续更新)
UIButton 文档翻译 继承 UIControl; UIView; UIResponder; NSObject 协议 UIFocusEnvironment,UIAppearanceContaine ...
- Ark组件设计随想(一)
Ark组件是L.Skyler自工作以来不断积累和优化的快速开发胶水架. Ark的目标是帮助开发人员简单快速的开始一个新的项目并且尽可能的复用已有功能.让项目开发不受一些基础组件开发影响. Ark定义了 ...
- oracle系统参数修改
create pfile='/home/oracle/sss.ora' from spfile; create spfile from pfile='/home/oracle/sss.ora'; al ...
- BestCoder Round #75 1003 - King's Order
国王演讲后士气大增,但此时战争还没有结束,国王时不时要下发命令. 由于国王的口吃并没有治愈,所以传令中可能出现:“让第三军-军-军,到前线去” 这样的命令.由于大洋国在军队中安插了间谍 , 战事紧急, ...
- Prim算法(普里姆算法)
描述: 一个连通图的生成树是指一个极小连通子图,它含有图中的全部顶点,但只有足以构成一棵树的 n-1 条边.我们把构造连通网的最小代价生成树成为最小生成树.而Prim算法就是构造最小生成树的一种算法. ...
- Linux 计算某文件夹下的所有文件的md5值
使用find 命令 find /root -type f -print0 |xargs -0 md5sum >a.md5 校验的话 md5sum -c a.md5