如何使用 Robotium 单击微调器中的第一项? [英] How do I click the first item in a spinner using Robotium?

查看:43
本文介绍了如何使用 Robotium 单击微调器中的第一项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在旋转器中向上滚动以选择 Robotium 测试用例中的第一项时遇到问题.这是我的代码:

I am having problems scrolling up in a spinner to select the first item in a Robotium test case. Here is my code:

int pos = solo.getCurrentSpinners().get(0).getSelectedItemPosition();
solo.pressSpinnerItem(0, 0 - pos);

pos 在我调试时为 1,但即使我命令它按下 -1,Robotium 仍然按下索引 1 上的微调器.我做错了什么?

pos is 1 when I debug, but Robotium still presses the spinner on index 1 even though I order it to press on -1. What am I doing wrong?

谢谢马库斯

推荐答案

似乎他们现在取消了这些课程.我自己刚刚遇到了这个问题,但找到了一种正确且通用的方法.

Seems they took those classes out now. Just ran into this myself but found a way to do this properly and generically.

// 0 is the first spinner in the layout
View view1 = solo.getView(Spinner.class, 0);
solo.clickOnView(view1);
solo.scrollToTop(); // I put this in here so that it always keeps the list at start
// select the 10th item in the spinner
solo.clickOnView(solo.getView(TextView.class, 10)); 

这篇关于如何使用 Robotium 单击微调器中的第一项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆