0

我希望有人可以帮助我解决这个问题,在 ddms 层次结构中如下:

(0) ListView
    (0) LinearLayout
        (0) LinearLayout
            (0)TextView:Value 1
            (1)TextView:Value 2
            (2)TextView:Value 3
        (1)View
        (2) LinearLayout
    (1) LinearLayout
        (0) LinearLayout
            (0)TextView:Value 4
            (1)TextView:Value 5
            (2)TextView:Value 6
        (1)View
        (2) LinearLayout

我试图做的是使用机器人来确认文本视图中的值。我的问题是第二组视图具有相同的资源 ID,例如值 1 和值 4 的资源 ID 均为 com.myapp.this:id/TopEntry

有没有办法使用robotium逐步定位视图,即获取视图0、1、0等。

目前我检查视图内容的代码是:

public String checkView(String theview, String expected)

{
       string actual = "";
       string result = "";
       TextView view = (TextView) solo.getView(theview);
       actual = (String) view.getText();
       assertEquals("viewChecked",expected,actual);

--------- code continues ---------------


}

因此,对于我的示例,我将使用以下方法调用代码:

checkView("TopEntry","Value 1");
checkView("TopEntry","Value 4"); <---------------and heeeeers the problem
4

1 回答 1

2

Solo.getView(int id, int index) 是你应该使用的。索引将从 0 变为 X,具体取决于共享相同 ID 的视图数量。

于 2014-06-02T11:53:17.237 回答