Liuyvhao

人呢,要有梦想。万一实现了呢?

Google官方版下拉刷新控件SwipeRefreshLayout解析

转载请标明出处:http://blog.csdn.net/liu1252247624/article/details/51557349

效果图如下:

布局文件:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/swipe"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.lg.swiperefreshlayoutdemo.MainActivity">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ListView
            android:id="@+id/listview"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </RelativeLayout>

</android.support.v4.widget.SwipeRefreshLayout>

MainActivity中代码:

public class MainActivity extends AppCompatActivity implements SwipeRefreshLayout.OnRefreshListener {
    private SwipeRefreshLayout swipeRefreshLayout;
    private ListView listView;
    private String[] names = new String[]{"郭靖", "黄蓉", "杨过", "小龙女"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe);
        swipeRefreshLayout.setOnRefreshListener(this);

        listView = (ListView) findViewById(R.id.listview);
    }

    @Override
    public void onRefresh() {
        listView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, names));
        swipeRefreshLayout.setRefreshing(false);
        Toast.makeText(this, "刷新成功", Toast.LENGTH_SHORT).show();
    }
}

很简单,可以根据具体的需求而更改

源码地址:http://download.csdn.net/detail/liu1252247624/9538062

阅读更多
版权声明:本文为博主原创文章,欢迎转载,转载务必注明文章出处,作者信息。 https://blog.csdn.net/liu1252247624/article/details/51557349
个人分类: Android开发笔记
想对作者说点什么? 我来说一句

SwipeRefreshLayoutDemo

2014年04月15日 1.42MB 下载

Google官网下拉刷新SwipeRefreshLayout

2014年12月25日 1.13MB 下载

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭