答案 0 :(得分:1)
经过一番研究后,我找到了DataInteraction.atPosition()
和DataInteraction.onChildView()
。例如,我可以做
onData(instanceOf(BaseballCard.class))
.atPosition(4)
.onChildView(withId(R.id.checkmark))
.perform(click());
答案 1 :(得分:1)
如果您的行布局允许单击该行来设置CheckBox,您可以使用它来单击ListView行:
onData(anything()).atPosition(4).perform(click());
否则,您可以直接点击CheckBox而不知道其ID:
onData(anything())
.atPosition(4)
.onChildView(withClassName(Matchers.containsString("CheckBox")))
.perform(click());
然后您可以断言CheckBox已被选中:
onData(anything())
.atPosition(4)
.onChildView(withClassName(Matchers.containsString("CheckBox")))
.check(matches(isChecked()));