API doc:http://developer.android.com/reference/android/support/v4/widget/SwipeRefreshLayout.html

Google在support v4 19.1版本推出了一个下拉刷新组件SwipeRefreshLayout,使用起来方便,效果优美,但要注意的是其布局中只能有一个直接子布局。使用步骤如下:

1.在xml中,加载android.support.v4.widget.SwipeRefreshLayout

 

        


2.使用

 

package com.example.testswiperefreshlayout;import android.os.Bundle;import android.os.Handler;import android.annotation.SuppressLint;import android.app.Activity;import android.support.v4.widget.SwipeRefreshLayout;import android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener;import android.view.Menu;import android.view.View;import android.view.ViewGroup;import android.widget.BaseAdapter;import android.widget.ListView;import android.widget.TextView;public class MainActivity extends Activity implements OnRefreshListener {private SwipeRefreshLayout mSwipeRefreshLayout;private ListView mList;@SuppressLint("InlinedApi")@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);mList = (ListView) findViewById(R.id.list);mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.layout_containter);mSwipeRefreshLayout.setColorSchemeResources(android.R.color.holo_blue_light,android.R.color.holo_green_light,android.R.color.holo_orange_light,android.R.color.holo_red_light);mSwipeRefreshLayout.setOnRefreshListener(this);}@Overridepublic void onRefresh() {new Handler().postDelayed(new Runnable() {@Overridepublic void run() {mSwipeRefreshLayout.setRefreshing(false);mList.setAdapter(new MyAdapter());}}, 5000);}class MyAdapter extends BaseAdapter {@Overridepublic int getCount() {return 10;}@Overridepublic Object getItem(int position) {// TODO Auto-generated method stubreturn null;}@Overridepublic long getItemId(int position) {// TODO Auto-generated method stubreturn 0;}@Overridepublic View getView(int position, View convertView, ViewGroup parent) {View inflate = null;TextView tvItem = null;if (convertView == null) {inflate = getLayoutInflater().inflate(R.layout.listview_item, null);tvItem = (TextView) inflate.findViewById(R.id.tv_item);inflate.setTag(tvItem);} else {inflate = convertView;tvItem = (TextView) inflate.getTag();}tvItem.setText("下拉刷新item"+position);return inflate;}}}

 

 

源码下载地址:http://download.csdn.net/detail/dennisruan/9433027

 

更多相关文章

  1. Android中更改SQLite数据库中的数据后,刷新ListView。
  2. Android的RemoteViews
  3. android开发笔记之Button的圆角和按下效果
  4. android基本的五大布局(3)
  5. Android群英传知识点回顾——第十章:Android性能优化
  6. Android布局属性集合
  7. Android(安卓)Tab类型主界面总结
  8. android ListView向上滑动隐藏标题,下拉显示标题栏
  9. Android电话Phone UI分析

随机推荐

  1. 如何从标准化表中获取最流行的标签?
  2. Mysql中FIND_IN_SET()和IN区别简析
  3. 在H2数据库中插入时间——函数“PARSEDAT
  4. beego_mysql,redis,mongo连接(20170307)
  5. 如何在MySQL数据库和JPA中使用Spring Boo
  6. 由于底层异常,无法加载连接类:'java.lang.N
  7. Mysql中文查询问题总结
  8. c#操作mysql事务是不是要在一个数据库连
  9. Mysql索引基础原理
  10. MySQL 示例数据库sakila