1

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

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

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

谢谢马库斯

4

3 回答 3

9

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

// 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)); 
于 2013-06-14T16:44:57.590 回答
-1

您是否只能获取视图并调用执行单击它?

solo.getCurrentSpinners().get(0).performClick()
于 2012-06-06T20:02:51.263 回答
-1

在这里与 Robotium 一起使用的 API 相当不稳定,所以我决定采用直接 API 路线:

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

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

于 2013-12-11T08:12:06.463 回答