android - How to use viewclient traverse method in AndroidViewClient -
i have following codes traverse listview in androidviewclient build list of accounts. works fine way because can't find more proper way pass variable list_accounts function findaccount() raises argument error must use globally. there way pass parameter 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) item in list_accounts: print "account:", item
you can this
def findaccount(la, view): if view.getclass() == 'android.widget.textview': text = view.gettext() if re.match(re.compile('.*@yahoo.com'), text): la.append(text) list_accounts = [] listview_id = vc.findviewbyidorraise('android:id/list') vc.traverse(root=listview_id, transform=lambda v: findaccount(list_accounts, v)) item in list_accounts: print "account:", item
but i'm not sure more clear , readable version.
however, can do
for tv in vc.findviewswithattribute('class', 'android.widget.textview', root=listview_id): text = tv.gettext() if re.match(re.compile('.*@yahoo.com'), text): list_accounts.append(text)
which guess improves readability.
Comments
Post a Comment