下拉刷新控件SwipeRefreshLayout
来源:互联网 发布:csgo声音优化 编辑:程序博客网 时间:2024/04/28 15:48
近期在学习android开发过程中,遇到了PullToRefresh控件,但是貌似很有没维护了吧,导入as中会出现问题。没有找到解决办法,只能用官方控件了。
Google提供了一个官方的下拉刷新控件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" android:paddingLeft="@dimen/activity_horizontal_margin"android:paddingRight="@dimen/activity_horizontal_margin"android:paddingTop="@dimen/activity_vertical_margin"android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"android:orientation="vertical"> <android.support.v4.widget.SwipeRefreshLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/swiperefresh"> <ListView android:id="@+id/lv" android:layout_width="match_parent" android:layout_height="match_parent"> </ListView> </android.support.v4.widget.SwipeRefreshLayout></LinearLayout>
MainActivity:
package com.example.administrator.usingswiperefreshlayout;
import android.os.AsyncTask;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.os.Handler;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
private SwipeRefreshLayout swiperefresh;private ArrayAdapter<String> adapter;private ListView lv;@Overrideprotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //建立一个List List<String> arr = new ArrayList(); arr.add("Hello"); arr.add("西瓜"); arr.add("Refresh"); swiperefresh = (SwipeRefreshLayout) findViewById(R.id.swiperefresh); swiperefresh.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);//设置刷新动画的颜色 lv = (ListView) findViewById(R.id.lv); //在listview中添加内容 adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,arr); lv.setAdapter(adapter); //刷新监听器 swiperefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { swiperefresh.setRefreshing(true);//开始刷新 //执行刷新后需要完成的操作 new Handler().postDelayed(new Runnable() { @Override public void run() { adapter.addAll("加入","成功");//添加两个条目 //刷新完成 Toast.makeText(MainActivity.this,"刷新完成",Toast.LENGTH_SHORT).show(); swiperefresh.setRefreshing(false);//结束刷新 } },4000);//刷新动画持续4秒 } });}}
如果遇到报错 Android Error inflating class SwipeRefreshLayout
那么
You need to use a full package name for SwipeRefreshLayout:
android.support.v4.widget.SwipeRefreshLayout
- 下拉刷新控件SwipeRefreshLayout
- SwipeRefreshLayout下拉刷新控件
- SwipeRefreshLayout-下拉刷新控件
- 下拉刷新控件---SwipeRefreshLayout
- 下拉刷新控件SwipeRefreshLayout
- Google 下拉刷新控件SwipeRefreshLayout
- Android 下拉刷新控件 SwipeRefreshLayout
- Android 下拉刷新控件SwipeRefreshLayout
- 新下拉刷新控件:SwipeRefreshLayout
- Android 下拉刷新控件SwipeRefreshLayout
- android 控件 下拉刷新 SwipeRefreshLayout
- Android 下拉刷新控件SwipeRefreshLayout
- 下拉刷新控件SwipeRefreshLayout使用
- MaterialDesign--下拉刷新控件--SwipeRefreshLayout
- Google下拉刷新控件SwipeRefreshLayout
- 官方下拉刷新控件SwipeRefreshLayout自动刷新
- Android官方下拉刷新控件 SwipeRefreshLayout
- Google support4 下拉刷新控件 SwipeRefreshLayout
- ASP.NET MVC应用中浏览器无法发出Ajax请求的问题解决一例
- C# 程序员最常犯的 10 个错误
- TCP调优
- oraoledbpus10.dll: 找不到指定的模块
- python 网络编程(二):IO 多路复用
- 下拉刷新控件SwipeRefreshLayout
- 从txt文件中读取配置信息
- 敏捷开发
- Angularjs $http 请求数据(get.post)
- 2.深入浅出JMS(二)--ActiveMQ简单介绍以及安装
- 动画
- 寻找单身狗
- jQuery中利用keyup事件和判断是否为汉字来实现动态搜索
- iOS资源分享