0

I use recycleView and to scroll to a particular view position and show a popupWindow below that view, if layout is not scrolled then popupWindow will not be shown at correct position since layout is not loaded. Recycleview's onScrollClickListener() doesn't get triggered when using recyclerView.scrollToTopPosition(pos) method. I have searched similar issue on stackoverflow and LayoutChangeListener() is suggested, but that also fails to work in my case.

Is there any other suggstion how to get onScroll callback when scrolling is done? I have been searching for a solution for the some hours now no luck.

My code

GenericFragmentButton fragmentButton = fragmentButtonsList.get(position).getFragmentButton();
int adapterPosition = groupAdapter.getAdapterPosition(fragmentButton);


layoutChangeListener = new View.OnLayoutChangeListener() {
    @Override
    public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
        showShowCase(position, fragmentButtonsList, fragmentButton);
    }
};

recyclerView.addOnLayoutChangeListener(layoutChangeListener);

recyclerView.scrollToPosition(adapterPosition);

enter image description here Showcase is supposed to show below the highlighted icon, but for some reasons when i use addOnLayoutChangeListener() it is shown at bottom, most of layout is hidden. I get this issue when i use addOnLayoutChangeListener() only so that's the reason i am searching for an alternate way to detect on scroll complete.

Update: Displaying popupWindow after a delay works but I don't think it's good solution.

final Handler handler = new Handler(Looper.getMainLooper());
handler.postDelayed(() -> showShowCase(position, fragmentButtonsList, fragmentButton), 200);
Amir Dora.
  • 2,831
  • 4
  • 40
  • 61
  • Have you taken a look at [RecyclerView.OnScrollListener](https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.OnScrollListener)? – Cheticamp May 14 '21 at 21:53
  • yes, onScrollClickListener's onStateChanged() doesn't get triggered if we use scrollToPosition(). – Amir Dora. May 14 '21 at 22:11
  • Right...then consider [this](https://stackoverflow.com/a/32679359/6287910) as an alternative. It may be better behaved than the layout change listener. – Cheticamp May 15 '21 at 00:30

0 Answers0