java - Android - ListView with AsyncTask implementation using JSOUP -


i need advice, because thing took me enough time angry on myself lack of knowledge... try make listview filled jsoup-extracted data. , jsoup part in asynctask. here code:

public class listaactivity extends actionbaractivity {      private list<string> mlist = new arraylist<>();     private listview mlistview;     private listadapter madapter;      public elements job;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_list);            mlistview = (listview) findviewbyid(r.id.list);          new newthread().execute();         madapter = new listadapter(this, mlist);         mlistview.setadapter(madapter);     }      public class newthread extends asynctask<string, void, string> {          @override         protected string doinbackground(string... arg) {              document doc;             try {                 doc = (document) jsoup.connect("http://www.somewebsite.com")                         .useragent("mozilla/5.0 (windows nt 6.1; wow64; rv:5.0) gecko/20100101 firefox/5.0").get();                  title = doc.select("h3.something-to-extract a[href]");                  (element titles : title) {                     mlist.add(titles.text()+"\n");                 }              } catch (ioexception e) {                 e.printstacktrace();             }              return null;         }     } } 

imo jsoup part, because when erase content od doinbackground , put inside

mlist.add("something 1"); mlist.add("something 2"); 

then works. please me somehow.

edit: want parse data html fragment:

<h2 class="title">       <a href="/jstpl/london/11697582"                  title="you have wait" class="titles">                     nothing else        </a> 

i wanted store "nothing else say" mlist, such titles existing in html code. parsing part alone works too.

you have call notifydatasetchanged on adapter

reflect changes in list provided adapter. -

override onpostexecute in newthread , call madapter.notifydatasetchanged()

        @override         protected void onpostexecute(string result) {             madapter.notifydatasetchanged();         }   

note : onpostexecute runs on main ui thread , not newthread, doinbackground runs inside newthread. , onpostexecute called when background thread done processing. since have updated list new items. notify adapter running on main thread. hope helps.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -