android - Xml pull parsing with customised adapter -


hi there new android platform ..off late trying hands on parsing rss feed using xml pull parser..my code works when use standard listview layout of android..but when try implement same code using customized list view , adapter ..no data been shown..i tested customized adapter raw data (not 1 fetch feed) , works perfectly..but when try use information fetched feed list view doesn't show data..have been trying quite time yet unable done..can please me in identifying mistakes committing...mind app functions non internet data not ones fetch feed..i trying extract title tag feed..any highly appreciated...the codes follows

mainactivity.java

public class mainactivity extends activity {     arraylist<feeddata> headlines;     list <string>title;     feeddata data = new feeddata();     list links;     string msg =null;     @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);         title = new arraylist<string>();         links = new arraylist();         headlines = new arraylist<feeddata>();          downloadtask runner =new downloadtask();         runner.execute();          for(int i=0;i<title.size();i++){             msg=title.get(i).tostring();             data.settitle(msg);             headlines.add(data);         }            feedadapter adapter= new    feedadapter(mainactivity.this,r.layout.imagefeed,headlines);         listview list = (listview)findviewbyid(r.id.lvmyfeed);         list.setadapter(adapter);        }      @override     public boolean oncreateoptionsmenu(menu menu) {         // inflate menu; adds items action bar if present.         getmenuinflater().inflate(r.menu.main, menu);         return true;     }     public class downloadtask extends asynctask<string,integer,string> {          @override         protected void onpreexecute() {             // todo auto-generated method stub             super.onpreexecute();         }           @override         protected string doinbackground(string... params) {             // todo auto-generated method stub         try{    url url = new url("http://www.pcworld.com/index.rss  ");         xmlpullparserfactory factory = xmlpullparserfactory.newinstance();         factory.setnamespaceaware(false);         xmlpullparser xpp = factory.newpullparser();              // xml input stream         xpp.setinput(getinputstream(url), "utf_8");           boolean insideitem = false;              // returns type of current event: start_tag, end_tag, etc..         int eventtype = xpp.geteventtype();         while (eventtype != xmlpullparser.end_document) {             if (eventtype == xmlpullparser.start_tag) {                  if (xpp.getname().equalsignorecase("item")) {                     insideitem = true;                 } else if (xpp.getname().equalsignorecase("title")) {                     if (insideitem)                         title.add(xpp.nexttext()); //extract headline                 } else if (xpp.getname().equalsignorecase("link")) {                     if (insideitem)                         links.add(xpp.nexttext()); //extract link of article                 }             }else if(eventtype==xmlpullparser.end_tag &&   xpp.getname().equalsignorecase("item")){                 insideitem=false;             }              eventtype = xpp.next(); //move next element         }      } catch (malformedurlexception e) {         e.printstacktrace();     } catch (xmlpullparserexception e) {         e.printstacktrace();     } catch (ioexception e) {         e.printstacktrace();     }          return null;     }         @override         protected void onpostexecute(string result) {             // todo auto-generated method stub             super.onpostexecute(result);          }           @override         protected void onprogressupdate(integer... values) {             // todo auto-generated method stub             super.onprogressupdate(values);         }         public inputstream getinputstream(url url) {                try {                    return url.openconnection().getinputstream();                } catch (ioexception e) {                    return null;                  }             }      }// end of downloadtask class        }` 

feeddata.java

      public class feeddata {     string headlines;      public feeddata()     {      }     public feeddata(string title) {         this.headlines=title;     }      public void settitle(string title){         this.headlines=title;     }     public string gettitle(){          return headlines;     }         }`        `feeddata.java         public class feeddata {     string headlines;      public feeddata()     {      }     public feeddata(string title) {         this.headlines=title;     }      public void settitle(string title){         this.headlines=title;     }     public string gettitle(){          return headlines;     }          } 

activity_main.xml

    <listview     android:id="@+id/lvmyfeed"     android:layout_width="match_parent"     android:layout_height="wrap_content" >     </listview>      </linearlayout> 

imagefeed.xml

 <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent" >      <imageview     android:id="@+id/ivimg"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_alignparentleft="true"     android:layout_alignparenttop="true"     android:layout_marginleft="28dp"     android:layout_margintop="38dp"     android:src="@drawable/ic_launcher" />      <textview     android:id="@+id/tvfeed"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_aligntop="@+id/ivimg"     android:layout_marginleft="78dp"     android:layout_margintop="14dp"     android:layout_torightof="@+id/ivimg"     android:text="headlines" />      </relativelayout> 

display or set adapter. listview after completed downloadtask means call

  feedadapter adapter= new    feedadapter(mainactivity.this,r.layout.imagefeed,headlines);   listview list = (listview)findviewbyid(r.id.lvmyfeed);   list.setadapter(adapter);   

in onpostexecute. behaviour of asynchtask different thread so, headlines title arraylist having no data why data not displaying on listview. after finishing downloadtask set adapter. hope you.


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -