How to use JSON to parse data into android application -
i can not understand code.
i beginner of android , java.
how work doinbackground(void... params), onpostexecute(string result).
how pass value on method mainacitivity.
please me.thanks
class downloadtask extends asynctask<void, void, string>{          @override         protected string doinbackground(void... params) {            string result=null;            try {               httpclient client=new defaulthttpclient();           httpget get=new httpget(urlstring);           httpresponse response=client.execute(get);            if(response.getstatusline().getstatuscode()==httpstatus.sc_ok){                inputstream in=response.getentity().getcontent();               bufferedreader reader=new bufferedreader(new inputstreamreader(in));               string line=reader.readline();               log.v(getclass().getsimplename(), line);               return line;            }           } catch (exception e) {             e.printstacktrace();             return null;         }                 return result;         }          @override         protected void onpostexecute(string result) {              progressdialog.dismiss();              try {                  jsonarray array=new jsonarray(result);                 (int = 0; < result.length(); i++) {                     jsonobject object=array.getjsonobject(i);                     string team1=object.getstring("t1");                     string team2=object.getstring("t2");                     allnews.add(team1 + "vs" + team2);                      adapter.notifydatasetchanged();                 }               } catch (exception e) {                 e.printstacktrace();             }           }        }      
this code asynctask - works in background , not on main ui thread - post/get request url defined in urlstring variable.
if request successful task returns ui thread in method onpostcreate result of json data. parses json , notifies current adapter (of listview probably) there's new/changed data.
if it's not code suggest write own takes more time understand code write 1 of own.
-- edit --
see example here more knowledge async-task parameters
Comments
Post a Comment