MaterialRefreshLayout 使用實例

package com.frame.activity;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.widget.Toast;

import com.cjj.MaterialRefreshLayout;
import com.cjj.MaterialRefreshListener;
import com.frame.R;

/**
 * Created by syd on 2016/10/9.
 */
public class TestActivity extends Activity {

    MaterialRefreshLayout materialRefreshLayout ;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.test_activity_test);


        materialRefreshLayout = (MaterialRefreshLayout) findViewById(R.id.refresh);
        //支持上拉加載更多
        materialRefreshLayout.setLoadMore(true);
        materialRefreshLayout.setMaterialRefreshListener(new MaterialRefreshListener() {
            @Override
            public void onRefresh(final MaterialRefreshLayout materialRefreshLayout) {
               new Handler().postDelayed(new Runnable() {
                   @Override
                   public void run() {
                       //下拉刷新更多
                       Toast.makeText(TestActivity.this,"onRefresh...",Toast.LENGTH_LONG).show();
                       materialRefreshLayout.finishRefresh();
                   }
               }, 3000);
            }

            @Override
            public void onRefreshLoadMore(final MaterialRefreshLayout materialRefreshLayout) {
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        //上拉加載更多
                        Toast.makeText(TestActivity.this,"onRefreshLoadMore...",Toast.LENGTH_LONG).show();
                        materialRefreshLayout.finishRefreshLoadMore();
                    }
                }, 3000);
            }
        });


    }



}




<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">




    <com.cjj.MaterialRefreshLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/refresh"
        app:wave_color="@color/material_green"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >


     <ListView
         android:background="#FF0000"
         android:layout_width="match_parent"
         android:layout_height="match_parent"></ListView>

    </com.cjj.MaterialRefreshLayout>

</LinearLayout>



參考鏈接:https://github.com/android-cjj/Android-MaterialRefreshLayout/blob/master/README-cn.md








                       

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章