How to populate a spinner Android from a php page? -


i have populate spinner php page : http://sce.jelocalise.fr/mobile/ajax/getdevices.php?email=info@mediacom-i.fr&password=thedevil1 i've read lots of tutorials spinners , way populate them failed adapt in code. here's looks on iphone (i have adapt iphone app android version) : http://img15.hostingpics.net/pics/665348img0017.png

i have display "vhc_name" in spinner , retrieve both "vhc_login" , "vhc_password" connect user. i've done working connection, need retrieve ids connect user. appreciated.

i've found solution :

string readfeed = readfeed();  arraylist<devices> devices = new arraylist<devices>(); arraylist<string> devicesnames = new arraylist<string>();  try {    jsonarray jsonarray = new jsonarray(readfeed);     (int = 0; < jsonarray.length(); i++) {     jsonobject jsonobject = jsonarray.getjsonobject(i);     devices device = new devices();     device.setname(jsonobject.optstring("vhc_name"));     device.setid(jsonobject.optstring("vhc_login"));     devices.add(device);     devicesnames.add(jsonobject.optstring("vhc_name"));    } } catch (exception e) { } spinner myspinner = (spinner)findviewbyid(r.id.mydevicesspinner); myspinner.setadapter(new arrayadapter<string>(this, android.r.layout.simple_spinner_dropdown_item, devicesnames));  } 

readfeed method downloads url ids :

public string readfeed() { stringbuilder builder = new stringbuilder(); httpclient client = new defaulthttpclient(); string userauth = param.getparam("user_webbsite_identifier").getvalue(); string userpass = param.getparam("user_webbsite_password").getvalue();  httpget httpget = new httpget("http://sce.jelocalise.fr/mobile/ajax/getdevices.php?email="+userauth+"&password="+userpass+""); try {   httpresponse response = client.execute(httpget);   statusline statusline = response.getstatusline();   int statuscode = statusline.getstatuscode();   if (statuscode == 200) {     httpentity entity = response.getentity();     inputstream content = entity.getcontent();     bufferedreader reader = new bufferedreader(new inputstreamreader(content));     string line;     while ((line = reader.readline()) != null) {       builder.append(line);     }   } else {     log.e(mydevices.class.tostring(), "failed download file");   } } catch (clientprotocolexception e) { } catch (ioexception e) { } return builder.tostring(); } 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -