我剛開始使用Calabash
,並且遇到了listview。Calabash Android通過ListView循環檢查
對於每個listview行,我想檢查一些文本和圖像視圖的存在。
但是我不確定如何循環瀏覽listview?
喜歡的東西
foreach list_item in listview
check text label with id
check image view with id
end
任何幫助,將不勝感激。
我剛開始使用Calabash
,並且遇到了listview。Calabash Android通過ListView循環檢查
對於每個listview行,我想檢查一些文本和圖像視圖的存在。
但是我不確定如何循環瀏覽listview?
喜歡的東西
foreach list_item in listview
check text label with id
check image view with id
end
任何幫助,將不勝感激。
我不確定在這種情況下使用foreach,但你可以根據列表中的索引號來完成。 喜歡的東西項目獲取數,然後通過他們的循環移動使用的兩個選項
getListView().setSelection(21);
對於平滑滾動:
getListView().smoothScrollToPosition(21);
從這個帖子https://stackoverflow.com/a/7561660/1165581通過HandlerExploit
然後爲每個項目檢查圖像和文字。
我已經在我的項目中使用了它,它的工作原理希望它可以幫助你。
在您的場景:
然後我滾動與 「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
@ userMod2下面檢查解決方案 -
當您使用
myList.getAdapter()。getView(I,NULL,NULL)
你所得到的項目視圖的新實例,試試
ListView.getChildAt(position)
方法這樣
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);
}
}