android - Simple jsoup Java HTML Parser Will Not Update TextView -


i'm attempting update textview using web data via jsoup

http://jsoup.org/

for reason never seems update textview table data url i'm attempting gather data from.

any suggestions?

i've looked on quite bit , cannot seem spot i'm doing wrong - i'm sure it's simple.

xml:

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:paddingbottom="@dimen/activity_vertical_margin"     android:paddingleft="@dimen/activity_horizontal_margin"     android:paddingright="@dimen/activity_horizontal_margin"     android:paddingtop="@dimen/activity_vertical_margin"     tools:context=".mainactivity" >      <textview         android:layout_width="wrap_content"         android:layout_height="wrap_content"             android:id="@+id/textview01"         android:text="@string/hello_world" />  </relativelayout> 

source:

public class mainactivity extends activity {      textview tv;     string url = "http://sheriff.org/apps/arrest/results.cfm?lname=abbott&fname=laurea";     string tr;     document doc;      @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);          tv = (textview) findviewbyid(r.id.textview01);         new mytask().execute(url);     }      private class mytask extends asynctask<string, void, string> {          progressdialog prog;          string title = "";          @override         protected void onpreexecute() {             prog = new progressdialog(mainactivity.this);             prog.setmessage("loading....");             prog.show();         }          @override         protected string doinbackground(string... params) {             try {                 doc = jsoup.connect(params[0]).get();                 element tableelement = doc.select(".datagrid").first();                  elements tablerows = tableelement.select("tr");                 (element row : tablerows) {                     elements cells = row.select("td");                     if (cells.size() > 0) {                         system.out.println(                                 cells.get(0).text() + "; " + cells.get(1).text() + "; " + cells                                         .get(2).text() + "; " + cells.get(3).text());                     }                 }             } catch (ioexception e) {                 e.printstacktrace();             }             return title;         }           @override         protected void onpostexecute(string result) {             super.onpostexecute(result);             prog.dismiss();             tv.settext(result);         }     } } 

edit in response first answer - still no fix:

public class mainactivity extends activity {      textview tv;     string url = "http://sheriff.org/apps/arrest/results.cfm?lname=abbott&fname=laurea";     string tr;     document doc;      @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);          tv = (textview) findviewbyid(r.id.textview01);         new mytask().execute(url);     }      private class mytask extends asynctask<string, void, string> {          progressdialog prog;          string title = "";          @override         protected void onpreexecute() {             prog = new progressdialog(mainactivity.this);             prog.setmessage("loading....");             prog.show();         }          @override         protected string doinbackground(string... params) {             try {                 doc = jsoup.connect(params[0]).get();                 element tableelement = doc.select(".datagrid").first();                  elements tablerows = tableelement.select("tr");                 (element row : tablerows) {                     elements cells = row.select("td");                     if (cells.size() > 0) {                          title = cells.get(0).text() + "; " + cells.get(1).text() + "; " +                                   cells.get(2).text() + "; " + cells.get(3).text();                     }                 }             } catch (ioexception e) {                 e.printstacktrace();             }             return title;         }           @override         protected void onpostexecute(string result) {             super.onpostexecute(result);             prog.dismiss();             tv.settext(result);         }     } } 

i tried:

public class mainactivity extends activity {  textview tv; string url = "http://sheriff.org/apps/arrest/results.cfm?lname=abbott&fname=laurea"; string tr; document doc;  @override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);      tv = (textview) findviewbyid(r.id.textview01);     new mytask().execute(url); }  private class mytask extends asynctask<string, void, string> {      progressdialog prog;      string title = "";      @override     protected void onpreexecute() {         prog = new progressdialog(mainactivity.this);         prog.setmessage("loading....");         prog.show();     }      @override     protected string doinbackground(string... params) {         try {             doc = jsoup.connect(params[0]).get();             element tableelement = doc.select(".datagrid").first();              elements tablerows = tableelement.select("tr");             (element row : tablerows) {                 elements cells = row.select("td");                 if (cells.size() > 0) {                      title = cells.get(0).text() + "; " + cells.get(1).text() + "; " +                               cells.get(2).text() + "; " + cells.get(3).text();                 }             }         } catch (ioexception e) {             e.printstacktrace();         }         return title;     }       @override     protected void onpostexecute(string title) {         super.onpostexecute(title);         prog.dismiss();         tv.settext(title);     } } } 

1) don't assign title variable.

2) don't use system.out.*. it's console programs. in android, use log

in doinbackground() change code to:

 title = cells.get(0).text() + "; " + cells.get(1).text() + "; " +   cells.get(2).text() + "; " + cells.get(3).text()); 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -