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 ...
随机推荐
- 子级Repeater获取 父级Repeater
第一种方法,子级Repeater中绑定父级的某个字段: <%# DataBinder.Eval((Container.NamingContainer.NamingContainer as Rep ...
- android开发时间和日期的代码实现工具类(一)
android开发时间和日期工具类的代码实现: package com.gzcivil.utils; import android.annotation.SuppressLint; import an ...
- Lazarus中TreeView导出XML以及XML导入TreeView
本来说是要给自己的某程序加一个xml导出功能,但是自己也没接触过xml,加之delphi和lazarus的xml部分还都不一样,折腾好久(整一天)才解决问题.. 如下是作为导出功能的组件部分: uni ...
- hdu3525
题目大意:某个大学有个2个校区,此大学有n(1<=n<=10000)个运动员,这n个运动员在每个校区都挑选了m(1<=m<=10)个拉拉队.现在每个校区(A/B)中,这m*n个 ...
- [MFC]解决回车键 ESC 默认关闭窗口的一般方法
在一般情况下编写的对话框程序,用户在运行的时候,如果不注意按下了ENTER或者ESC键,程序就会立刻退出,之所以会这样,是因为按下Enter键时,Windows就会自动去找输入焦点落在了哪一个按钮上, ...
- 前端开发面试题收集 HTML
Doctype是什么?说明特点. <!doctype>声明必须处于HTML文档的头部,在标签之前. <!doctype>声明不是一个HTML标签,是一个用于告诉浏览器使用哪种H ...
- python--执行文件的绝对路径
1.__file__属性对应文件名. 2.os.path.realpath(__file__)这样就可以得到文件的绝对路径.
- [问题解决] /home目录占用率100%
今天发现一个比较奇怪的现象,linux系统下一个目录挂在存储下,df -Th 显示该目录使用率100%, du 该目录显示只用了2%, 后来发现是由于进程占用了被删掉的文件空间导致.举例如下: [ro ...
- Invalidate(TRUE)与Invalidate(FALSE)区别(前者会发送WM_ERASEBKGND消息全部刷新,然后使用WM_PAINT消息绘制,而后者只发送WM_PAINT消息)
使用Invalidate(TRUE)函数时,它会向消息队列中添加了WM_ERASEBKGND和WM_PAINT两个消息. 使用Invalidate(FALSE)函数时,它只会向消息队列中添加了WM_P ...
- Windows下让Git记住用户名密码(https)
最近开始跟老板共同维护公司的框架代码,于是毫不犹豫地选择了Git这个驰名的版本控制系统(公司使用的是TFS,但外网访问老是断线). 选择的托管平台是OSChina,原因是其可以新建私有项目. 在拉取和 ...