//获取gridview的元素
View view = solo.getView(R.id.gridViewFavs);
//获取imageView的元素集合,其中第一个参数为所需要获得view的类型.clas,第二个参数为该view的父view类型
ArrayList<ImageView> gv = solo.getCurrentViews(ImageView.class, view);
//获取imageview下的第index个子view
ImageView imageView = (ImageView) gv.get(1);
************************************************************************
robotium 官方api
getCurrentViews
public <T extends android.view.View> ArrayList<T> getCurrentViews(Class<T> classToFilterBy, android.view.View parent)
- Returns an ArrayList of Views matching the specified class located under the specified parent.
-
-
Parameters:
-
classToFilterBy- return all instances of this class. Examples are:Button.classorListView.class -
parent- the parentViewfor where to start the traversal
Returns:
-
an
ArrayListofViews matching the specifiedClasslocated under the specifiedparent
-
view获取代码
可以获得view焦点,然后点击
方法一:
Activity act = solo.getCurrentActivity();
//通过String的id获取int的id
int id = act.getResources().getIdentifier("content", "id",
act.getPackageName());
//获取View
View view = act.findViewById(id);
//获得子view
ArrayList<View> childView = solo.getViews(view);
View imageview = childView.get(0);
solo.clickOnView(imageview);
方法二
ArrayList<View> gg = solo.getCurrentViews(View.class);
View view = gg.get(0);//此数为向下滑动
System.out.println(view);
solo.clickOnView(view);
本文介绍了使用Robotium测试工具如何获取GridView中的子View。通过`solo.getView()`和`solo.getCurrentViews()`方法结合,可以定位并操作特定的子View。同时,文中提供了两种方式,包括通过资源ID获取View以及直接获取当前屏幕上的View集合,实现对GridView中子View的选择和点击。
636

被折叠的 条评论
为什么被折叠?



