parse.com - Android, looping through Parse data, assigning to ArrayAdapter -
i looping through data in android, using parse data. came way user information; larger goal create model of data can use in array adapter, can create custom list view (as described here) in example, data hard-coded, not pulled database.
public static arraylist<midwifefirm> getusers() { //parse data users parsequery<parseuser> query = parseuser.getquery(); query.orderbyascending(parseconstants.key_practice_name); query.findinbackground(new findcallback<parseuser>() { @override public void done(list<parseuser> users, parseexception e) { if (e == null) { final list<parseuser> mmidwives; mmidwives = users; string usertype; string[] midwives = new string[mmidwives.size()]; string[] yearsofexperience = new string[mmidwives.size()]; string[] education = new string[mmidwives.size()]; string[] philosophy = new string[mmidwives.size()]; int = 0; (parseuser user : mmidwives) { usertype = user.getstring("usertype"); if (!arrays.aslist(midwives).contains(usertype) && usertype != "patient") { midwives[i] = user.getstring("practicename"); yearsofexperience[i] = user.getstring("yearsofexperience"); education[i] = user.getstring("education"); philosophy[i] = user.getstring("practicephilosophy"); arraylist<midwifefirm> midwifefirm = new arraylist<midwifefirm>(); midwifefirm.add(new midwifefirm(midwives[i], yearsofexperience[i], education[i], philosophy[i])); return midwifefirm; } } } } }); } the intention every user not have type patient, collect data them, store in arraylist.
on return statement, though, there error: cannot return value method void return type.
i may on complicating this...read through various sources model this...in end, want display list of information specific users, after user makes selection of city...it therefore display information medical practices in city.
thanks help
michael
the code won't compile in form sent it.
you make asynchronous call when use findinbackground. means code calls carry on after calls it. won't wait finish, doesn't care anymore.
the right way deal type of code writing logic want , manipulating results in callback. first thing change return type of getusers void.
now getusers merely says: "ok, please find in background , here i'll let thing in done()".
public static void getusers() { //parse data users parsequery<parseuser> query = parseuser.getquery(); query.orderbyascending(parseconstants.key_practice_name); query.findinbackground(new findcallback<parseuser>() { @override public void done(list<parseuser> users, parseexception e) { if (e == null) { // here manipulate list. set data structures // or whatever , call other methods `activity` or whatever, // passing data parameter } } }); } you need update code calls getusers , needs list of users, because, see, can't results straight away. may able move of code in done.
le: may want remove static modifier method.
Comments
Post a Comment