android - How to parse data from multiple URLs using asyncTask -


the main problem i'm unable return 2 value help. have tried lot of time no success. , guys i'm new please write answer respect code in advance.

here's code

    public class calculate extends asynctask<string, string, string> {         @override         protected void onpreexecute() {             super.onpreexecute();         }          @override         protected string doinbackground(string... params) {              try {                 uss = getjson("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.xchange%20where%20pair%20in%20(%22inrusd%22)&format=json&diagnostics=true&env=store%3a%2f%2fdatatables.org%2falltableswithkeys&callback=");                 jsonobject usjobj;                 usjobj = new jsonobject(uss);                 usresult = usjobj.getjsonobject("query").getjsonobject("results").getjsonobject("rate").getstring("rate");                   eurr = getjson("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.xchange%20where%20pair%20in%20(%22inreur%22)&format=json&diagnostics=true&env=store%3a%2f%2fdatatables.org%2falltableswithkeys&callback=");                 jsonobject eurjobj;                 eurjobj = new jsonobject(eurr);                 eurresult = eurjobj.getjsonobject("query").getjsonobject("results").getjsonobject("rate").getstring("rate");             } catch (jsonexception e) {                 // todo auto-generated catch block                 e.printstacktrace();             } catch (clientprotocolexception e) {                 // todo auto-generated catch block                 e.printstacktrace();             } catch (ioexception e) {                 // todo auto-generated catch block                 e.printstacktrace();             }             return eurresult + usresult;             ////problem here don't know how return 2 or more value/////"         }          @override         protected void onpostexecute(string usresult) {             valueus = double.parsedouble(usresult);             inputus = lengthvalue * valueus;             us.settext("" + inputus);              valueeur = double.parsedouble(eurresult);             inputeur = lengthvalue * valueeur;             eur.settext("" + inputeur);         }      }       public string getjson(string url) throws clientprotocolexception, ioexception {          stringbuilder build = new stringbuilder();         httpclient client = new defaulthttpclient();         httpget httpget = new httpget(url);         httpresponse response = client.execute(httpget);         httpentity entity = response.getentity();         inputstream content = entity.getcontent();         bufferedreader reader = new bufferedreader(new inputstreamreader(content));         string con;         while ((con = reader.readline()) != null) {             build.append(con);         }         return build.tostring();     } } 

you should not try cram string. there better data structures hold multiple values: array, vector, list, etc. declare asynttask as:

public class calculate extends asynctask<string, string, string[]> 

and doinbackgorund method this:

@override protected string doinbackground(string... params) {     string[] result = new string[numresults];      ...     result[0] = usjobj.getjsonobject("query").getjsonobject("results").getjsonobject("rate").getstring("rate");      ...     result[1] = usjobj.getjsonobject("query").getjsonobject("results").getjsonobject("rate").getstring("rate");      ...      return result; } 

and onpostexecute be

@override protected void onpostexecute(string[] usresult) {     ... } 

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -