PullreFreshLibrary(PullToRefreshListView)上拉刷新,下拉加载(—)

原创 2016年05月31日 14:48:08

MainActivity.xml
第三方架包下载地址:https://github.com/chrisbanes/Android-PullToRefresh
解压后使用其中的library

<com.handmark.pulltorefresh.library.PullToRefreshListView
        xmlns:ptr="http://schemas.android.com/apk/res-auto"  
        android:id="@+id/expand_list"  
        android:layout_width="match_parent"  
        android:layout_height="wrap_content"  
        ptr:ptrDrawable="@drawable/indicator_bg_top"   
        ptr:ptrAnimationStyle="flip"  
        ptr:ptrHeaderBackground="#383838"  
        ptr:ptrHeaderTextColor="#FFFFFF"  
        />  

MainActivity.class

import java.util.ArrayList;

import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshBase.Mode;
import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener2;
import com.handmark.pulltorefresh.library.PullToRefreshListView;

import android.os.Bundle;
import android.os.Handler;
import android.app.Activity;
import android.view.Menu;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class MainActivity extends Activity  {

    private PullToRefreshListView mExpandList;
    private ArrayList<String> list;
    private ArrayAdapter<String> adapter;
    Handler hand=new Handler(){
        public void handleMessage(android.os.Message msg) {
            if(msg.what==0){
                adapter.notifyDataSetChanged();
                mExpandList.onRefreshComplete();
            }
        };
    };
    @Override
    protected void onCreate(Bundle savedInstanceState)  {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        list = new ArrayList<String>();
        getData();
        mExpandList = (PullToRefreshListView)  findViewById(R.id.expand_list); 
        mExpandList.setMode(Mode.BOTH);
        adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1, list);
        mExpandList.setAdapter(adapter);
        mExpandList.setOnRefreshListener(new OnRefreshListener2<ListView>()  {

            @Override
            public void onPullDownToRefresh(PullToRefreshBase refreshView) {
                // TODO Auto-generated method stub
                list.clear();
                getData();
                hand.sendEmptyMessageDelayed(0, 2000);
            }

            @Override
            public void onPullUpToRefresh(PullToRefreshBase refreshView) {
                // TODO Auto-generated method stub
                getData();
                hand.sendEmptyMessageDelayed(0, 2000);
            }
        }); 
    }

    private void getData() {
        for(int i=0;i<10;i++){
            list.add(i+"");
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }    
}

PullToRefreshListView下拉刷新与上拉加载

【声明】转载请注明出处,此文出自指尖飞落的博客:http://blog.csdn.net/huntersnail ——尊重作者,知识无价,交流无限! 前言:下拉刷新是Android项目中经常要用...

下拉刷新上拉加载之PullToRefreshListView的用法

一、导入library github地址:https://github.com/chrisbanes/Android-PullToRefresh as中file-》new-》import modu...

PullToRefreshListView上拉加载更多,下拉刷新

使用PullToRefreshListView实现上拉加载更多,下拉刷新。 源码如下: 首先在pullToRefresh包下创建PullableListView.java: /pullToRefres...

上拉刷新 下拉加载更多-PullToRefreshListView的简介

1) 在开发过程中经常需要上拉下拉操作,比如查看新闻时需要上拉刷新、下拉加载更多,这里就要用到PullToRefreshListView第三方库。 2) lib库下载地址: http://downlo...

简单实现标题栏悬浮状态,使用PullToRefreshListView上拉加载下拉刷新

title_xml:     android:layout_width="match_parent"     android:layout_height="match_parent"  ...

Android自定义上拉加载下拉刷新PullToRefreshListView

转自http://blog.csdn.net/allen315410/article/details/39965327   最近项目中要用到刷新和加载的功能,网上查了有好多关于刷新和加载的例子,挑了...

PullToRefreshListView进阶(三)----->上拉加载、下拉刷新!

activity_listview_refresh_mani.xml

PullToRefreshListView上拉加载,下拉刷新 刷新网络数据 简单实现ListView显示网络数据

1、依赖: compile 'com.google.code.gson:gson:2.6.2' compile 'com.github.userswlwork:pull-to-refresh:1.0...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:PullreFreshLibrary(PullToRefreshListView)上拉刷新,下拉加载(—)
举报原因:
原因补充:

(最多只允许输入30个字)