robotium gridview获取子view方法(笔记)

转自:http://blog.csdn.net/eleven521/article/details/16359001

//获取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.class or ListView.class
parent - the parent View for where to start the traversal
Returns:
an ArrayList of Views matching the specified Class located under the specified parent

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


你可能感兴趣的:(android,测试,GridView,自动化)