美文网首页
转:SwipeRefreshLayout + RecyclerV

转:SwipeRefreshLayout + RecyclerV

作者: 魏成 | 来源:发表于2017-07-14 14:06 被阅读22次

    mRecyclerView = (RecyclerView) findViewById(android.R.id.list);
    mRecyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() {

    @Override
    public void onScrollStateChanged(RecyclerView recyclerView,
    int newState) {
    super.onScrollStateChanged(recyclerView, newState);
    if (newState == RecyclerView.SCROLL_STATE_IDLE
    && lastVisibleItem + 1 == adapter.getItemCount()) {
    mSwipeRefreshWidget.setRefreshing(true);
    // 此处在现实项目中,请换成网络请求数据代码,sendRequest .....
    handler.sendEmptyMessageDelayed(0, 3000);
    }
    }

    @Override
    public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);
    lastVisibleItem = mLayoutManager.findLastVisibleItemPosition();
    }
    });

    mRecyclerView.setHasFixedSize(true);
    mLayoutManager = new LinearLayoutManager(this);
    mRecyclerView.setLayoutManager(mLayoutManager);
    mRecyclerView.setItemAnimator(new DefaultItemAnimator());

    adapter = new SampleAdapter();
    mRecyclerView.setAdapter(adapter);

    相关文章

      网友评论

          本文标题:转:SwipeRefreshLayout + RecyclerV

          本文链接:https://www.haomeiwen.com/subject/rqcgbttx.html