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

本文介绍了使用Robotium测试工具如何获取GridView中的子View。通过`solo.getView()`和`solo.getCurrentViews()`方法结合,可以定位并操作特定的子View。同时,文中提供了两种方式,包括通过资源ID获取View以及直接获取当前屏幕上的View集合,实现对GridView中子View的选择和点击。

//获取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);


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值