【问题标题】:Expandable listview scrolls when using robotium to click on a image in listview使用robotium单击列表视图中的图像时,可扩展的列表视图滚动
【发布时间】:2012-12-05 10:57:47
【问题描述】:

当我使用 Robotium 单击可展开列表视图的第一项上的图像时,如下所示:

ListView listview = getCurrentListView().getChildAt(1); //get feed listview.
for(ImageView view : solo.getCurrentImageViews(listview))
{
   if(view.getId() == R.id.image) //all images in the feed listview shares the same ID.
   {
      solo.clickonview(view);
      break;  //get the first image then break the loop.
   }
}

可展开的列表视图滚动。 使用 logcat,我敢肯定,我得到了第一张图片。但是当solo.clickonview 时,它不起作用,并且listview 开始滚动到最后一个。 为什么会这样?
有什么方法可以完成这个场景吗?

【问题讨论】:

    标签: java android unit-testing robotium


    【解决方案1】:

    它会点击这张图片吗? 我不确定,如果您为 getCurrentImageViews 提供正确的父级。

    尝试使用这个:

    for (View v : solo.getCurrentImageViews()) {
         if (v.getId() == R.id.image)
              solo.clickonview(v);
    }
    

    【讨论】:

    • 我也试过这个,但也失败了。我可以在第一个 listview 项目上获取图像,但是当 solo.clickonview 时,它似乎不起作用,并且 listview 开始滚动到最后一个项目。
    【解决方案2】:

    在点击之前使用下面的方法并将滚动设置为false:

    waitForView(View view, int timeout, boolean scroll)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-03
      相关资源
      最近更新 更多