android - How so I return multiple JSON values to multiple text views? -
i did research json
. found tutorials jsonarray
, not how make allow multiple text views jsonobject
. should have method, add parameters or what?
this json
,
{ "name": "iss", "id": 25544, "latitude": -16.621580566205, "longitude": -22.573425077475, "altitude": 403.33965999684, "velocity": 27615.932538565, "visibility": "daylight", "footprint": 4421.7128198729, "timestamp": 1478617317, "daynum": 2457701.1263542, "solar_lat": -16.808913358406, "solar_lon": 310.46294067763, "units": "kilometers" }
here code if want see it,
public class isstatusactivity extends appcompatactivity { string longitst; jsonparser jsonparser = new jsonparser(); textview latitude; textview longitude; string lat; string longit; jsonobject jobj = null; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.isstatus); latitude = (textview) findviewbyid(r.id.coordinates); new retrievedata().execute(); } class retrievedata extends asynctask<string, string, string> { @override public string doinbackground(string... args) { jobj = jsonparser.makehttprequest("http://api.wheretheiss.at/v1/satellites/25544"); try { lat = "latitude: " + jobj.getstring("latitude"); longit = "longitude :" + jobj.getstring("longitude"); } catch (jsonexception e) { // todo auto-generated catch block e.printstacktrace(); } return lat; } @override protected void onpostexecute(string lat) { latitude.settext(lat); longit.settext(longitude); } } }
you doing wrong
in onpostexecute() instead of longit.settext(longitude) use longitude.settext(longit) longitude textview reference , longit string.it goes this
1. use string lat , long global variables.
2. after making network call set lat , long values.
3. in onpostexecute settext textviews.
Comments
Post a Comment