Q:

Wait until recyclerview has scrolled to position

I am working with a recyclerview where I have to select last item in the recyclerview.
I first scroll to the recyclerview and then call performClick() method on the selected item.
Here is the code. 
int latestPostIndex = reactionsListAdapter.getItemCount() - 1;
rvReactionsList.scrollToPosition(latestPostIndex);
rvReactionsList.getChildAt(latestPostIndex).performClick();

latestPostIndex is populated correctly. Problem is the performClick is called before the scroll is complete and hence app crashes.
How can I make performClick() wait until scrollToPosition() is complete?

A:

You can assign a RecyclerView.OnScrollListener to your RecyclerView and listen to onScrollStateChanged wait for a scroll to be finished:
int latestPostIndex = reactionsListAdapter.getItemCount() - 1;
rvReactionsList.scrollToPosition(latestPostIndex);
rvReactionsList.addOnScrollListener(new RecyclerView.OnScrollListener() {
    @Override
    public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
        super.onScrollStateChanged(recyclerView, newState);
        if(newState == RecyclerView.SCROLL_STATE_IDLE 
            && linearLayoutManager.findLastVisibleItemPosition() == latestPostIndex)
            linearLayoutManager.findViewByPosition(latestPostIndex).performClick();

    }
});

P.S: Don't forget to replace 
rvReactionsList.getChildAt(latestPostIndex) with linearLayoutManager.findViewByPosition(latestPostIndex) as getChildAt doesn't return the last cell of RecyclerView..

