Android Robolectric单击Recycler查看条目 [英] Android Robolectric Click RecyclerView Item
问题描述
有什么方法可以用Robolectric模拟对RecyclerView
项目的点击?
Is there any way to simulate a click on a RecyclerView
item with Robolectric?
到目前为止,我已经尝试将View
放置在RecyclerView
的第一个可见位置,但这始终是null
. getChildCount()
始终返回0
,而findViewHolderForPosition
始终为null
.适配器从getItemCount()
返回一个非0的数字(适配器中肯定有项目).
So far, I have tried getting the View
at the first visible position of the RecyclerView
, but that is always null
. It's getChildCount()
keeps returning 0
, and findViewHolderForPosition
is always null
. The adapter returns a non-0 number from getItemCount()
(there are definitely items in the adapter).
我正在使用Robolectric 2.4快照.
I'm using Robolectric 2.4 SNAPSHOT.
推荐答案
似乎是问题所在,需要在Robolectric中手动测量和布置RecyclerView
.调用此即可解决问题:
Seems like the issue was that RecyclerView
needs to be measured and layed out manually in Robolectric. Calling this solves the problem:
recyclerView.measure(0, 0);
recyclerView.layout(0, 0, 100, 10000);
这篇关于Android Robolectric单击Recycler查看条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!