Wednesday, 15 September 2010

java - How to pass data to UI thread -



java - How to pass data to UI thread -

good evening.

i have activity this. in handlemessage have access largetext field , can alter it, can't smth whith stringlinks field, or each other field not ui element(like textview, button, edittext, etc). how can add together stringlinks ?

public class aboutusactivity extends activity { handler h; textview largetext; list<string> stringlinks; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); stringlinks = new arraylist<string>(); largetext = (textview) findviewbyid(r.id.textview1); h = new handler() { public void handlemessage(android.os.message msg) { htmlparser parser; stringbuilder result = new stringbuilder(); seek { parser = new htmlparser(string.valueof(msg.getdata())); list<tagnode> links = parser.getcontentbyclassname("ab"); (iterator<tagnode> iterator = stringlinks.iterator(); iterator .hasnext();) { tagnode divelement = (tagnode) iterator.next(); result.append(divelement.gettext().tostring()); } } grab (exception e) { e.printstacktrace(); } largetext.settext(newhtml); //work stringlinks.add(newhtml); //doesn't work } }; myhttpclientusage connect = new myhttpclientusage(h); seek { connect.getinfoabout(); } grab (httpexception e) { e.printstacktrace(); } }

}

i dont know if understood correctly.

if did, can utilize asynctask class

check out main methods, doinbackground executes in separate thread , onpostexecute runs in ui thread. can comunicate each other passing objects, , can publish progress of task.

it looks swingworker (maybe used if programmed swing applications).

java android asynchronous

No comments:

Post a Comment