maiyuqiang
maiyuqiang
2017-01-22 07:25
采纳率: 37.5%
浏览 2.9k

RecyclerView下拉刷新时快速上拉崩溃

图片说明

下拉用的SwipeRefreshLayout

  mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout);
        mSwipeRefreshLayout.setColorSchemeResources(android.R.color.holo_blue_bright,
                android.R.color.holo_green_light,
                android.R.color.holo_orange_light,
                android.R.color.holo_red_light);

        adapter = new DangJianRecyclerViewAdapter(this,list);

         manager = new LinearLayoutManager(this,LinearLayoutManager.VERTICAL,false);
        mRecyclerView.setLayoutManager(manager);
        mRecyclerView.setItemAnimator(new DefaultItemAnimator());

        mRecyclerView.setAdapter(adapter);
        mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                list.clear();
                pageIndex = 1;
                loadData(pageIndex+"");
            }
        });
        mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
                if(newState == RecyclerView.SCROLL_STATE_IDLE){
                    int lastVisiblePosition = manager.findLastVisibleItemPosition();
                    if(lastVisiblePosition >= manager.getItemCount() - 1){
                        pageIndex +=1;

                        loadData(pageIndex+"");
                    }
                }
            }
        });

正常速度上拉下拉没什么问题,但是下拉时迅速上拉就会报错

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • hide_on_bush
    hide_on_bush 2017-01-24 08:36
    已采纳

    数据请求下来之后再clear

    点赞 3 评论
  • qq_29191601
    那天青色 2017-01-22 07:56

    下拉的时候list清空了,然后你迅速上拉导致数据还未加载吧.就出现越界异常

    点赞 评论
  • Mr_dsw
    Antway_ 2017-01-23 09:16

    图片说明
    根据这个错误来看,是数组越界。可能是你的数据被清空出现的。你可以在你刷新处理的业务中打个断点

    点赞 评论

相关推荐