基于layout的下拉刷新

https://github.com/dodola/FanPullToRefresh

<com.fanpulltorefresh.PullToRefresh
        android:id="@+id/pullDownView1" android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        >
        <!--content-->
        <ListView android:id="@+id/listview1" android:layout_width="fill_parent"
            android:layout_height="fill_parent"></ListView>
    </com.fanpulltorefresh.PullToRefresh>
public class MainActivity extends Activity implements
        PullToRefresh.UpdateHandle {
    PullToRefresh refresh;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        refresh = (PullToRefresh) this.findViewById(R.id.pullDownView1);
        refresh.setUpdateHandle(this);
        ListView view = (ListView) this.findViewById(R.id.listview1);
        view.setAdapter(new ArrayAdapter<String>(this,
                android.R.layout.simple_expandable_list_item_1, getData()));
    }

    private List<String> getData() {

        List<String> data = new ArrayList<String>();

        for (int i = 1; i < 30; i++) {
            data.add("测试数据" + i);
        }

        return data;
    }

    @Override
    public void onUpdate() {
        new MyThread(handler).start();
    }

    class MyThread extends Thread {
        private Handler handler;

        public MyThread(Handler handler) {
            this.handler = handler;

        }

        @Override
        public void run() {
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {

                e.printStackTrace();
            }
            Message msg = handler.obtainMessage();
            handler.sendMessage(msg);
            super.run();
        }

    }

    private final Handler handler = new Handler(Looper.getMainLooper()) {
        public void handleMessage(Message msg) { // 处理Message,更新ListView
            SimpleDateFormat formatter = new SimpleDateFormat(
                    "yyyy年MM月dd日   HH:mm:ss     ");

            Date curDate = new Date(System.currentTimeMillis());// 获取当前时间
            String str = formatter.format(curDate);
            refresh.endUpdate(str);
        }
    };
}

https://github.com/chrisbanes/Android-PullToRefresh

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值