第三方上下拉刷新

 

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

    <com.scwang.smartrefresh.layout.SmartRefreshLayout
        android:id="@+id/srl"
        android:layout_weight="1"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/rec"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </com.scwang.smartrefresh.layout.SmartRefreshLayout>




</LinearLayout>
package com.example.mothyue.view;

import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;

import com.example.mothyue.R;
import com.example.mothyue.bean.Bean;
import com.example.mothyue.cantract.IuWei;
import com.example.mothyue.presenter.Presenter;
import com.example.mothyue.util.MyAdapter;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;

import java.util.List;

public class MainActivity extends AppCompatActivity implements IuWei.DataView {
    private RecyclerView rec;
    private SmartRefreshLayout srl;
    int page = 1;
    int count = 10;
    private Presenter presenter;

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


        srl = (SmartRefreshLayout) findViewById(R.id.srl);
        rec = (RecyclerView) findViewById(R.id.rec);

        presenter = new Presenter(this);

        srl.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {
                srl.finishRefresh(2000);
                presenter.getData(page, count);

            }
        });
        srl.setOnLoadMoreListener(new OnLoadMoreListener() {
            @Override
            public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
                srl.finishLoadMore(2000);
                count++;
                presenter.getData(page, count);
                Log.i("wjr", "onLoadMore: "+ page +"  "+ count);
            }
        });


        presenter.getData(page,count);

    }

    @Override
    public void showSuccess(Object o) {
        Bean bean = (Bean) o;
        List<Bean.ResultBean> list = bean.getResult();
        inint(list);
    }

    private void inint(List<Bean.ResultBean> list) {

        GridLayoutManager manager = new GridLayoutManager(this, 2);
        rec.setLayoutManager(manager);
        MyAdapter myAdapter = new MyAdapter(list, this);
        rec.setAdapter(myAdapter);

    }

    @Override
    public void showFail(Throwable o) {

    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值