Add DATE and TIME to RSS FEED - Android -


i have rss feed 3 tabs, every tab fetches rss link. rss working want add date , time below every feed in part of picturelink, , make picturelink. can me please.

here full code:

rsstabsactivity.java

  public class rsstabsactivity extends tabactivity {   @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_rss_tabs);     tabhost tabhost = gettabhost();     intent artintent = new intent().setclass(this, rsschannelactivity.class);     artintent.putextra("rss-url", "http://www1.up.edu.ph/index.php/feed/");     string arttabname = getresources().getstring(r.string.tab_art);     tabspec arttabspec = tabhost.newtabspec(arttabname)  .setindicator(arttabname, getresources().getdrawable(r.drawable.rss_tab_art))  .setcontent(artintent);     tabhost.addtab(arttabspec);     intent techintent = new intent().setclass(this, rsschannelactivity.class);     techintent.putextra("rss-url", "http://www1.up.edu.ph/index.php/feed/");     string techtabname = getresources().getstring(r.string.tab_tech);     tabspec techtabspec = tabhost.newtabspec(techtabname)  .setindicator(techtabname, getresources().getdrawable(r.drawable.rss_tab_tech))  .setcontent(techintent);     tabhost.addtab(techtabspec);     intent sportsintent = new intent().setclass(this, rsschannelactivity.class);     sportsintent.putextra("rss-url", "http://www1.up.edu.ph/index.php/feed/");     string sportstabname = getresources().getstring(r.string.tab_sports);     tabspec sportstabspec = tabhost.newtabspec(sportstabname)  .setindicator(sportstabname, getresources().getdrawable(r.drawable.rss_tab_sports))  .setcontent(sportsintent);     tabhost.addtab(sportstabspec);     tabhost.setcurrenttab(1); }  } 

rsschannelactivity.java

public class rsschannelactivity extends activity {  private rsschannelactivity local;   @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);      setcontentview(r.layout.activity_rss_channel);     string rssurl = (string)getintent().getextras().get("rss-url");     local = this;     getrssdatatask task = new getrssdatatask();     task.execute(rssurl); } private class getrssdatatask extends asynctask<string, void, list<rssitem> > {     @override     protected list<rssitem> doinbackground(string... urls) {         try {             rssreader rssreader = new rssreader(urls[0]);             return rssreader.getitems();          } catch (exception e) {             log.e("rsschannelactivity", e.getmessage());         }          return null;     }      @override     protected void onpostexecute(list<rssitem> result) {          listview itcitems = (listview) findviewbyid(r.id.rsschannellistview);          arrayadapter<rssitem> adapter = new arrayadapter<rssitem>         (local,android.r.layout.simple_list_item_1, result);         itcitems.setadapter(adapter);         itcitems.setonitemclicklistener(new listlistener(result, local));     } }  } 

rssitem.java

public class rssitem {  private string title;  private string link;  public string gettitle() {     return title; }  public void settitle(string title) {     this.title = title; }  public string getlink() {     return link; }  public void setlink(string link) {     this.link = link; }  @override public string tostring() {     return title; }  } 

listlistener.java

public class listlistener implements onitemclicklistener {  list<rssitem> listitems;  activity activity;  public listlistener(list<rssitem> alistitems, activity anactivity) {     listitems = alistitems;     activity  = anactivity; } public void onitemclick(adapterview<?> parent, view view, int pos, long id) {     intent = new intent(intent.action_view);     i.setdata(uri.parse(listitems.get(pos).getlink()));      activity.startactivity(i);  }   } 

rssparsehandler.java

public class rssparsehandler extends defaulthandler {  private list<rssitem> rssitems;  private rssitem currentitem;  private boolean parsingtitle;  private stringbuffer currenttitlesb;  private boolean parsinglink;  public rssparsehandler() {     rssitems = new arraylist<rssitem>(); }  public list<rssitem> getitems() {     return rssitems; }  @override public void startelement(string uri, string localname, string qname, attributes                    attributes) throws saxexception {     if ("item".equals(qname)) {         currentitem = new rssitem();     } else if ("title".equals(qname)) {         parsingtitle = true;          currenttitlesb = new stringbuffer();     } else if ("link".equals(qname)) {         parsinglink = true;     } }  @override public void endelement(string uri, string localname, string qname) throws      saxexception   {     if ("item".equals(qname)) {         rssitems.add(currentitem);         currentitem = null;     } else if ("title".equals(qname)) {          parsingtitle = false;          if (currentitem != null) {             // set item's title here             currentitem.settitle(currenttitlesb.tostring());         }      } else if ("link".equals(qname)) {         parsinglink = false;     } }  @override public void characters(char[] ch, int start, int length) throws saxexception {     if (parsingtitle) {         if (currentitem != null) {              currenttitlesb.append(new string(ch, start, length));         }     } else if (parsinglink) {         if (currentitem != null) {             currentitem.setlink(new string(ch, start, length));             parsinglink = false;         }     } }  } 

rssreader.java

public class rssreader {  private string rssurl;  public rssreader(string rssurl) {     this.rssurl = rssurl; } public list<rssitem> getitems() throws exception {     // sax parse rss data     saxparserfactory factory = saxparserfactory.newinstance();     saxparser saxparser = factory.newsaxparser();      rssparsehandler handler = new rssparsehandler();      saxparser.parse(rssurl, handler);      return handler.getitems(); } }  

rsstabslayout.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" tools:context=".rsstabsactivity" >  <tabhost     android:id="@android:id/tabhost"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:layout_alignparentleft="true"     android:layout_alignparenttop="true">      <linearlayout         android:layout_width="match_parent"         android:layout_height="match_parent"         android:orientation="vertical" >          <tabwidget             android:id="@android:id/tabs"             android:layout_width="match_parent"             android:layout_height="15dp"             android:visibility="invisible" >         </tabwidget>          <framelayout             android:id="@android:id/tabcontent"             android:layout_width="match_parent"             android:layout_height="match_parent" >              <linearlayout                 android:id="@+id/tab_art"                 android:layout_width="match_parent"                 android:layout_height="match_parent" >             </linearlayout>              <linearlayout                 android:id="@+id/tab_tech"                 android:layout_width="match_parent"                 android:layout_height="match_parent" >             </linearlayout>              <linearlayout                 android:id="@+id/tab_sports"                 android:layout_width="match_parent"                 android:layout_height="match_parent" >             </linearlayout>          </framelayout>     </linearlayout> </tabhost>   </relativelayout> 

rsschannellayout.xml

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" >  <listview     android:id="@+id/rsschannellistview"     android:layout_width="fill_parent"     android:layout_height="fill_parent"  > </listview>  </linearlayout> 

you need create custom arrayadapter:

public class customarrayadapter extends arrayadapter<rssitem> {    private final list<rssitem> alistitems   private final activity context;    public interactivearrayadapter(activity context, list<rssitem> alistitems) {     super(context, r.layout.yourcustomlayout, alistitems);     this.context = context;     this.alistitems = alistitems;   }    @override   public view getview(int position, view convertview, viewgroup parent) {     view view = null;     if (convertview == null) {       layoutinflater inflator = context.getlayoutinflater();       view = inflator.inflate(r.layout.yourcustomlayout, null);       final viewholder viewholder = new viewholder();       viewholder.text = (textview) view.findviewbyid(r.id.title);       viewholder.time = (textview) view.findviewbyid(r.id.time);       view.settag(viewholder);     } else {       view = convertview;     }     viewholder holder = (viewholder) view.gettag();     holder.text.settext(alistitems.get(position).getname());     holder.time.settext(alistitems.get(position).gettime());     return view;   }     static class viewholder {     protected textview text;     protected textview time;   } }  

your custom xml :

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" > <textview     android:id="@+id/title"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="@+id/title"     android:textsize="30px" > </textview>  <textview     android:id="@+id/time"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="@+id/time"     android:textsize="30px" > </textview> 


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -