<?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) {
}
}