问题
I've just started using Calabash
and have come across a listview.
For each listview row I want to check the presence of some text and image view.
However I'm unsure how can i loop through the listview?
Something like
foreach list_item in listview
check text label with id
check image view with id
end
Any help would be appreciated.
回答1:
I am not sure about using foreach in this case, but you could do it based on index number in the list. Something like get count of item, then in a loop move through them by using of of two options
getListView().setSelection(21);
For a smooth scroll:
getListView().smoothScrollToPosition(21);
From this post https://stackoverflow.com/a/7561660/1165581 by HandlerExploit
And then for each item check the image and text.
回答2:
@userMod2 Check below solutions -
- Solution 1
When you use
myList.getAdapter().getView(i,null,null)
you are getting a new instance of the item view, try the
ListView.getChildAt(position)
method like this
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
}
Solution 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); } }
回答3:
I have used this in my project and it works hope it helps you.
In your Scenario:
Then I scroll to text with "xyz" label and touch it
Declare the step as follows:
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
来源:https://stackoverflow.com/questions/31120310/calabash-android-looping-through-a-listview-to-check