使用es preSSO单击视图内RecyclerView项目 [英] Using Espresso to click view inside RecyclerView item
问题描述
我如何使用长者preSSO点击里面的 RecyclerView 项的具体看法?我知道我可以用点击在位置0的项目:
How can I use Espresso to click a specific view inside a RecyclerView item? I know I can click the item at position 0 using:
OnView为(withId(R.id.recyclerView))
.perform(RecyclerViewActions.actionOnItemAtPosition(0,点击()));
onView(withId(R.id.recyclerView))
.perform(RecyclerViewActions.actionOnItemAtPosition(0, click()));
不过,我需要点击里面的项目,而不是项目本身的特定视图。
But I need to click on a specific view inside that item and not on the item itself.
在此先感谢。
- 编辑 -
要更precise:我有一个 RecyclerView ( R.id.recycler_view
)的项目是 CardView ( R.id.card_view
)。在每个 CardView 我有四个按钮(除其他事项外),我想点击一个特定的按钮( R.id.bt_deliver
)。
To be more precise: I have a RecyclerView (R.id.recycler_view
) which items are CardView (R.id.card_view
). Inside each CardView I have four buttons (amongst other things) and I want to click on a specific button (R.id.bt_deliver
).
我想用长者$ P $的新功能PSSO 2.0,但我不知道这是可能的。
I would like to use the new features of Espresso 2.0, but I'm not sure that is possible.
如果没有可能,我想用这样的事情(用托马斯·凯勒code):
If not possible, I wanna use something like this (using Thomas Keller code):
onRecyclerItemView(R.id.card_view, ???, withId(R.id.bt_deliver)).perform(click());
但我不知道放什么的问号。
but I don't know what to put on the question marks.
推荐答案
您可以使用自定义视图动作做到这一点。
You can do it with customize view action.
public class MyViewAction {
public static ViewAction clickChildViewWithId(final int id) {
return new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return null;
}
@Override
public String getDescription() {
return "Click on a child view with specified id.";
}
@Override
public void perform(UiController uiController, View view) {
View v = view.findViewById(id);
if (v != null) {
v.performClick();
}
}
};
}
}
然后,您可以点击它
Then you can click it with
onView(withId(R.id.rv_conference_list)).perform(
RecyclerViewActions.actionOnItemAtPosition(0, MyViewAction.clickChildViewWithId(R.id. bt_deliver)));
这篇关于使用es preSSO单击视图内RecyclerView项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!