1.Mactivity
public class MainActivity extends AppCompatActivity implements IShowView { @BindView(R.id.rec) RecyclerView rec; @BindView(R.id.swp) SwipyRefreshLayout swp; private ShowPresenter showPresenter; private int page=1; private Handler handler=new Handler(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ButterKnife.bind(this); showPresenter = new ShowPresenter(this); showPresenter.getPresenter(page+""); //调用弱引用解决内存泄漏 showPresenter.attachView(this); // LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity()); // linearLayoutManager.setOrientation(OrientationHelper.VERTICAL); //rec.setLayoutManager(linearLayoutManager); LinearLayoutManager layoutManager = new LinearLayoutManager(this){ @Override public boolean canScrollVertically() { return false; } }; rec.setLayoutManager(layoutManager); swp.setColorSchemeColors(R.color.colorAccent,R.color.colorPrimary,R.color.colorPrimaryDark); swp.setDirection(SwipyRefreshLayoutDirection.BOTH); //设置上拉刷新事件 swp.setOnRefreshListener(new SwipyRefreshLayout.OnRefreshListener() { @Override public void onRefresh(int index) { page=1; showPresenter.getPresenter(page+""); handler.postDelayed(new Runnable() { @Override public void run() { swp.setRefreshing(false); } },2000 ); } @Override public void onLoad(int index) { page++; showPresenter.getPresenter(page+""); handler.postDelayed(new Runnable() { @Override public void run() { swp.setRefreshing(false); } },2000 ); } }); } @Override public void getView(List<DataBean> data) { MyAdapter myAdapter = new MyAdapter(this, data); rec.setAdapter(myAdapter); } @Override protected void onDestroy() { super.onDestroy(); //解决内存泄漏 showPresenter.detachView(); } }