学习笔记 Tianmao 篇 materialRefreshLayout 下拉刷新 控件的使用

1.加入相应的dependence依赖:

dependencies {
compile 'com.cjj.materialrefeshlayout:library:1.3.0'
}   

2.materialRefreshLayout布局 包裹RecyclerView

 <com.cjj.MaterialRefreshLayout
    android:id="@+id/material_refresh_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="10dp"
    app:overlay="true"
    app:wave_show="true"
    app:wave_color="#90ffffff"
    app:progress_colors="@array/material_colors"
    app:wave_height_type="higher"
    >

    <android.support.v7.widget.RecyclerView
        android:id="@+id/care_recycler_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    </android.support.v7.widget.RecyclerView>
</com.cjj.MaterialRefreshLayout>

3.然后实例化materialRefreshLayout对象

private MaterialRefreshLayout materialRefreshLayout;
materialRefreshLayout = (MaterialRefreshLayout) view.findViewById(R.id.material_refresh_view);

4.初始化materialRefreshLayout 及其 下滑刷新的 和上滑加载的 具体 操作 的监听器

/**
* 初始化materialRefreshLayout 及其 下滑刷新的 和上滑加载的 具体 操作 的监听器
*
* @param view
*/

private void initRefreshLayout(final View view) {

    materialRefreshLayout.setLoadMore(true);                 //设置是否价值啊更多
    materialRefreshLayout.setMaterialRefreshListener(new MaterialRefreshListener() {
        @Override
        public void onRefresh(MaterialRefreshLayout materialRefreshLayout) {
            refreshData(view);

        }

        @Override
        public void onRefreshLoadMore(MaterialRefreshLayout materialRefreshLayout) {
            super.onRefreshLoadMore(materialRefreshLayout);
            loadData(view);
        }
    });


}

5.对上拉下拉操作refreshData(view); loadData(view);

//下拉刷新控件,刷新出数据
private void refreshData(View view) {
    if (currPage < carePageBean.getTotalPage()) {
        currPage = currPage + 1;
        state = STATE_DO_REFREH;
        initViewBean(view);
    } else {

        Toast.makeText(getContext(), "不能加载更多", Toast.LENGTH_SHORT).show();
        materialRefreshLayout.finishRefresh();
    }
}

//上拉刷新控件,属性出数据
private void loadData(View view) {
    if (currPage > 0) {
        currPage = currPage - 1;
        state = STATE_NEED_MORE;
        initViewBean(view);
    } else {

        Toast.makeText(getContext(), "不能加载更多", Toast.LENGTH_SHORT).show();
        materialRefreshLayout.finishRefreshLoadMore();
    }
}

6.进行RecycleView初始化操作数据获取啊配置什么的

/**
* 初始化ViewBean
*
* @param view
*/
private void initViewBean(final View view) {

    httpHelper.get(MyUrl.Content.getCareInfoUrl(currPage,pageSize), new SpotsCallBack<CarePageBean<CareFirstViewBean>>(getContext()) {


        @Override
        public void onSuccess(Response response, CarePageBean<CareFirstViewBean> newCarePageBean) {
            //初始化recycleList
            carePageBean = newCarePageBean;
            initRecycleList(newCarePageBean.getList());

            //初始化RecyclerView
            initRecyclerView(view);
        }

        @Override
        public void onError(Response response, int code, Exception e) {

        }
    });

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值