0

I am using RecyclerView with CarouselLayoutManager library and i want to detect the most elevated item.

I have the method below to know if the user scrolled the recyclerview and change the current most elevated recyclerview item.

   recyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() {
        int overallXScroll = 0;
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            overallXScroll = overallXScroll + dx;
            //if the scroll amount will change the recyclerView item order :
            if(overallXScroll > 100){
                Toast.makeText(MainActivity.this, "123", Toast.LENGTH_SHORT).show();
                overallXScroll = 0;
            }
            Log.i("check","overallXScroll->" + overallXScroll);
        }
    });

This method works very slow and with a delay , what can i do ?

Tamir Abutbul
  • 7,301
  • 7
  • 25
  • 53
  • Are the logs slow too? Or is it just the Toast? – SafalFrom2050 Jun 24 '18 at 18:57
  • I am getting the long on time but the toast is coming with a delay @SafalSharma – Tamir Abutbul Jun 24 '18 at 19:03
  • Have you checked logs? Are they slow too? – SafalFrom2050 Jun 24 '18 at 19:04
  • Toasts are not mean't to display very fast messages like you are implementing. They are only used to display one message for certain time(like you specified as Toast.LENGTH_SHORT). They will be displayed for that time before showing another one. Thus they are delayed. – SafalFrom2050 Jun 24 '18 at 19:08
  • Possibly useful, if queued `Toast`s are the problem: https://stackoverflow.com/a/27098246/2911458 – stkent Jun 24 '18 at 19:31
  • Actually, the Toast is just a test, what a really want to do is swap fragments when the most elevated item is changed, I will try to do it now that I know that what made the delay was the Toast cast time. – Tamir Abutbul Jun 24 '18 at 19:39

0 Answers0