SmartRefreshLayoutActivity.java 2.09 KB
Newer Older
1
package com.mayi.demo.view;
gao.chao committed
2

gao.chao committed
3 4 5 6
import android.os.Bundle;
import android.view.ViewGroup;
import android.widget.TextView;

gao.chao committed
7 8 9
import com.mayi.demo.ItemBean;
import com.mayi.fastdevelop.base.BaseListActivity;
import com.mayi.fastdevelop.util.DateUtil;
gao.chao committed
10 11 12 13

/**
 * git 地址:https://github.com/scwang90/SmartRefreshLayout
 */
gao.chao committed
14
public class SmartRefreshLayoutActivity extends BaseListActivity<ItemBean, SmartRefreshLayoutVH> {
gao.chao committed
15

gao.chao committed
16
    int max = 80;
gao.chao committed
17 18

    @Override
gao.chao committed
19
    protected void onCreate(Bundle savedInstanceState) {
gao.chao committed
20
        super.onCreate(savedInstanceState);
gao.chao committed
21 22
        title.setTextCenter("列表");
    }
gao.chao committed
23

gao.chao committed
24 25 26 27
    @Override
    protected SmartRefreshLayoutVH createVH(ViewGroup parent, int viewType) {
        SmartRefreshLayoutVH vh = new SmartRefreshLayoutVH(new TextView(parent.getContext()));
        vh.setLayoutVHListener(new SmartRefreshLayoutVH.SmartRefreshLayoutVHListener() {
gao.chao committed
28
            @Override
gao.chao committed
29 30
            public void onItemClick(ItemBean itemBean) {
                showToast(itemBean.getText());
gao.chao committed
31 32
            }
        });
gao.chao committed
33 34 35 36 37 38 39 40
        return vh;
    }

    @Override
    protected void onRefreshData() {
        dismssLoadMsg();
        stopLoadMoreData();
        handler.postDelayed(new Runnable() {
gao.chao committed
41
            @Override
gao.chao committed
42 43 44 45 46 47
            public void run() {
                list.clear();
                addData();
                startLoadMoreData();
                notifyData();
                finishRefresh();
gao.chao committed
48
            }
gao.chao committed
49
        }, 1000);
gao.chao committed
50 51
    }

gao.chao committed
52 53 54
    private void addData() {
        for (int i = 0; i < 20; i++) {
            list.add(new ItemBean(list.size() + "   " + DateUtil.getCurrentDate(), null));
gao.chao committed
55 56 57
        }
    }

gao.chao committed
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
    @Override
    protected void loadMoreData(int pageNumber) {
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                addData();
                notifyData();
                isLoadMore = false;
                if (list.size() >= max) {
                    stopLoadMoreData();
                    showLoadMsg("数据加载完成");
                } else {
                    dismssLoadMsg();
                }
            }
        }, 1000);
gao.chao committed
74
    }
gao.chao committed
75 76

}