繁体   English   中英

如何使用Robotium单击微调器中的第一项?

[英]How do I click the first item in a spinner using Robotium?

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

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

调试时pos是1,但是Robotium仍然按索引1上的微调器,即使我命令它按-1时也是如此。 我究竟做错了什么?

谢谢马库斯

看来他们现在把这些课都上了。 只是自己遇到了这个问题,但是找到了一种正确且通用的方法。

// 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)); 

您能否仅获取视图并调用执行单击?

solo.getCurrentSpinners().get(0).performClick()

与Robotium一起使用的API非常不稳定,因此我决定采用直接API路线:

instrumentation.runOnMainSync(new Runnable() {
    @Override
    public void run() {
        Spinner spinner = (Spinner) solo.getView(resourceId);
        spinner.setSelection(position, true);
    }
});

这不会显示微调框的弹出窗口,但会选择所需的项目。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM