android - How can I extract string from OnPostExecute to my Main Activity -


i'm still new, repeat, new in android studio , i'm trying display place name,vicinity,lat , long using listview. got listview ready couldnt string onpostexecute. tried using https://stackoverflow.com/a/12575319/5776859 did not work @ all, or maybe didnt correctly. hope me or show me proper way string , double onpostexecute.

public class placesdisplaytask extends asynctask<object, integer,  list<hashmap<string,string>>> {       jsonobject googleplacesjson;     googlemap googlemap;      @override     public list<hashmap<string, string>> doinbackground(object... inputobj) {          list<hashmap<string, string>> googleplaceslist = null;         places placejsonparser = new places();          try {             googlemap = (googlemap) inputobj[0];             googleplacesjson = new jsonobject((string) inputobj[1]);             googleplaceslist = placejsonparser.parse(googleplacesjson);         } catch (exception e) {             log.d("exception", e.tostring());         }          return googleplaceslist;     }      @override     protected void onpostexecute(list<hashmap<string,string>> list) {          (int = 0; < 3; i++) {              hashmap<string, string> googleplace = list.get(i);             double lat = double.parsedouble(googleplace.get("lat"));             double lng = double.parsedouble(googleplace.get("lng"));             string placename = googleplace.get("place_name");             string vicinity = googleplace.get("vicinity");          }     } } 

a less tedious way accomplish you're trying perform whatever task requires returned value within onpostexecute(). can input references context using constructor , store them global variables use.

another way can set return type in signature of class list<hashmap<string, string>> , can call <placesdisplaytask object>.execute().get() method. make background process synchronous i.e. block ui thread, waiting on result.

the last alternative can think of involves use of delegate described in link you've posted.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -