如何停止自动滚动RecyclerView?

时间:2018-06-27 12:44:20

标签: android android-recyclerview onclicklistener autoscroll

我有一个水平RecyclerView来显示当前周即将到来的生日的人。我已将自动滚动添加到RecyclerView,活动开始后RecyclerView开始滚动...

自动滚动RecyclerView ...的代码

 final int duration = 50;
            final int pixelsToMove = 10;
            final Handler mHandler = new Handler(Looper.getMainLooper());
            final Runnable SCROLLING_RUNNABLE = new Runnable() {
                @Override
                public void run() {
                    birthdayRV.smoothScrollBy(pixelsToMove, 0);
                    mHandler.postDelayed(this, duration);
                }
            };

            birthdayAdapter = new BirthdayAdapter(birthdayModelList, HomeActivity.this);
            final LinearLayoutManager layoutManager = new LinearLayoutManager(HomeActivity.this, LinearLayoutManager.HORIZONTAL, false);
            birthdayRV.setHasFixedSize(true);
            birthdayRV.setLayoutManager(layoutManager);
            birthdayRV.setAdapter(birthdayAdapter);

            birthdayRV.addOnScrollListener(new RecyclerView.OnScrollListener() {
                @Override
                public void onScrolled(final RecyclerView recyclerView, int dx, int dy) {
                    super.onScrolled(recyclerView, dx, dy);
                    int lastItem = layoutManager.findLastCompletelyVisibleItemPosition();
                    if (lastItem == layoutManager.getItemCount() - 1) {
                        mHandler.removeCallbacks(SCROLLING_RUNNABLE);
                        Handler postHandler = new Handler();
                        postHandler.postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                birthdayRV.setAdapter(null);
                                birthdayRV.setAdapter(birthdayAdapter);
                                birthdayRV.setClickable(true);
                                mHandler.postDelayed(SCROLLING_RUNNABLE, 2000);
                            }
                        }, 2000);
                    }
                }
            });
            mHandler.postDelayed(SCROLLING_RUNNABLE, 2000);

我在onCLickListner内的cardViews中设置了recylerView(adapter),以查看有关人员的详细信息,点击相应的cardViews ...

我的问题是recyclerView开始滚动时,clickListener不起作用...如果您需要进一步的说明,请询问...帮助我...

0 个答案:

没有答案