0

Description:

I am using RecyclerView with LinearLayoutManager horizontally. In this, i am trying to get the direction. Recyclerview is moving from left to right or right to left.

Here is my code:

holder.recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
            }

            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);

                if(dy > 0){
                    Log.e(TAG,"SCROLL =>"+"RIGHT");
                }else{
                    Log.e(TAG,"SCROLL =>"+"LEFT");

                }
//                int currentVisible=lManger.findFirstVisibleItemPosition();
//
//                Log.e(TAG,"FIRST VISIBLE=>"+firstVisible);
//                Log.e(TAG,"CURRENT VISIBLE=>"+currentVisible);
//                if(currentVisible > firstVisible){
//                    Log.e("RecyclerView scrolled: ", "scroll up!");
//                    if(temp!=blogBean1.getCount()) {
//                        if(temp > 1){
//                            holder.ivPrevious.setVisibility(View.VISIBLE);
//                        }
//                        temp++;
//                        Log.e(TAG,"UP TEMP VALUE IS=>"+temp);
//                        if(currentVisible+1==blogBean1.getCount()){
//                            holder.ivNext.setVisibility(View.GONE);
//                        }
//                    }
//                }else{
//                    Log.e("RecyclerView scrolled: ", "scroll down!");
//
//                    if(temp!=0) {
//                        temp--;
//                        Log.e(TAG,"TEMP VALUES IS=>"+temp);
//                        holder.ivPrevious.setVisibility(View.VISIBLE);
//                        holder.ivNext.setVisibility(View.VISIBLE);
//                    }
//                    else if(firstVisible==0 && currentVisible==0){
//                        Log.e(TAG,"BOTH ZERO=>"+firstVisible+"\t Another=>"+currentVisible);
//                        holder.ivPrevious.setVisibility(View.GONE);
//                        holder.ivNext.setVisibility(View.VISIBLE);
//                    }
//                }
//                firstVisible = currentVisible;
            }
        });

Problem:

When I touch my screen to scroll RecyclerView item. It goes into the multiple time in the scrollview.

How can I do it?

Ronak Thakkar
  • 2,515
  • 6
  • 31
  • 45
Milan Gajera
  • 962
  • 2
  • 14
  • 41
  • you can follow https://stackoverflow.com/questions/32035427/how-to-scroll-horizontal-recyclerview-programmatically –  Jun 10 '17 at 09:09
  • then https://developer.android.com/reference/android/support/v7/widget/RecyclerView.OnScrollListener.html –  Jun 10 '17 at 09:09
  • its for up/down https://stackoverflow.com/questions/29024058/recyclerview-scrolled-up-down-listener –  Jun 10 '17 at 09:10

0 Answers0