我正在使用RecyclerView,需要选择其中的最后一项。
首先滚动到RecyclerView最后一项,然后调用所选项目的performClick()方法。
以下是代码:
int latestPostIndex = reactionsListAdapter.getItemCount() - 1;
rvReactionsList.scrollToPosition(latestPostIndex);
rvReactionsList.getChildAt(latestPostIndex).performClick();
latestPostIndex已正确填充。问题在于performClick在滚动完成之前被调用,因此应用程序崩溃。
我该如何使performClick()等待scrollToPosition()完成后再执行?