1

我刚刚开始使用Calabash并遇到了一个列表视图。

对于每个列表视图行,我想检查一些文本和图像视图的存在。

但是我不确定如何遍历列表视图?

就像是

foreach list_item in listview
   check text label with id
   check image view with id
end

任何帮助,将不胜感激。

4

3 回答 3

1

我不确定在这种情况下是否使用 foreach,但您可以根据列表中的索引号进行操作。诸如获取项目计数之类的东西,然后在循环中通过使用两个选项来遍历它们

getListView().setSelection(21);

对于平滑滚动:

getListView().smoothScrollToPosition(21);

来自HandlerExploit的这篇文章https://stackoverflow.com/a/7561660/1165581

然后为每个项目检查图像和文本。

于 2015-06-30T04:15:20.790 回答
0

@userMod2 检查以下解决方案 -

  • 解决方案 1

当你使用

myList.getAdapter().getView(i,null,null)

您正在获得项目视图的新实例,请尝试

ListView.getChildAt(位置)

像这样的方法

 private void ButtonClick() {
    /** get all values of the EditText-Fields */
    View v;
    ArrayList<String> mannschaftsnamen = new ArrayList<String>();
    EditText et;
    for (int i = 0; i < myList.getCount(); i++) {
      v = myList.getAdapter().getView(i, null, null);
      et = (EditText) v.findViewById(i);
      mannschaftsnamen.add(et.getText().toString());
    }
    // Add your action code here
    // Add your action code here
 }
  • 解决方案 2

    public void onScroll(AbsListView v, int firstVisibleItem, int   visibleCount, int totalItemCount)
    {
    ListView lv = this.getListView();
    int childCount = lv.getChildCount();
    
    for (int i = 0; i < childCount; i++)
    {
        View v = lv.getChildAt(i);
        TextView tx = (TextView) v.findViewById(R.id.mytext);
        tx.setTextSize(textSize);
    }
    }
    
于 2016-07-12T07:59:52.823 回答
0

我已经在我的项目中使用了它,它可以工作,希望它可以帮助你。

在您的场景中:

然后我滚动到带有“xyz”标签的文本并触摸它

声明步骤如下:

Then /^I scroll to text with "([^\"]*)" label and touch it$/ do |name|
element="TextView text:'#{name}'"      
    if !element_exists(element)
            wait_poll(timeout: 20,
            timeout_message: 'Unable to find "Example"', :until_exists => "TextView text:'#{name}'") do
            scroll_down
     end
     if element_exists(element)
            touch element 
            sleep(10)
     else
            screenshot_and_raise "could not find the cell"
     end
     else
            touch element
            sleep(10)
     end    
end
于 2015-09-09T05:46:15.237 回答