I have the following codes to traverse a ListView in AndroidViewClient to build a list of accounts. It works fine but is it a good way to do because I can't find a more proper way to pass the variable list_accounts to the function findAccount() as it raises an Argument error so I must use it globally. Is there a way to pass a parameter to the transform method of vc.traverse() ?
def findAccount(view):
if view.getClass() == 'android.widget.TextView':
text = view.getText()
if re.match(re.compile('.*@yahoo.com'), text):
list_accounts.append(text)
list_accounts = []
listview_id = vc.findViewByIdOrRaise('id/no_id/11')
vc.traverse(root=listview_id, transform=findAccount)
for item in list_accounts:
print "account:", item