我希望有人可以帮我解决这个问题,在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
我想要做的是使用robotium来确认文本视图中的值。我的问题是第二组视图具有相同的资源ID,例如,值1和值4都具有com.myapp.this的资源ID: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
答案 0 :(得分:2)
Solo.getView(int id,int index)就是你应该使用的。索引将从0更改为X,具体取决于共享相同ID的视图数量。