android - Count item in xml -


i'm getting rss feed following:

        <item>         <caterory>sports</category>         <content:encoded>text 1......</content:encoded>         <title>title 1...</title>         </item>          <item>         <caterory>news</category>         <content:encoded>text 2......</content:encoded>         <title>title 2 ...</title>         </item>          <item>         <caterory>sports</category>         <content:encoded>text 3......</content:encoded>         <title>title 3 ...</title>         </item>           ......          <item>         <caterory>news</category>         <content:encoded>text x......</content:encoded>         <title>title x ...</title>         </item> 

i create list ,and listitems should named category name.so,if user click on sports,he see sports new, etc. how easy done? searching net haven't found similar. now, have created list witch returns me list categories (ex. if have 25 articles, list 25 categories,sometime same,as 1.sports,2.news,3.sports,...etc)

int position=1; if (feed.getitem(position).getcategory()!=null) {   for(int pos=0;pos<feed.getitemcount();pos++){      //feed.getitemcount();      slidemenuitem item2=new slidemenuitem();     item2.id = myitemcategory;     item2.icon = getresources().getdrawable(r.drawable.favorite_full);     item2.label = feed.getitem(pos).getcategory();     slidemenu.addmenuitem(item2); } 

sorry bad syntax,hope question understandable..:)

create set categories, eliminate duplicates. iterate set , add them 1 one menu.

http://docs.oracle.com/javase/6/docs/api/java/util/set.html

try this:

int position=1; if (feed.getitem(position).getcategory()!=null) {     set<string> categories = new hashset<string>();     for(int pos=0;pos<feed.getitemcount();pos++)         categories.add(feed.getitem(pos).getcategory();      for(string category : categories) {         slidemenuitem item2=new slidemenuitem();         item2.id = myitemcategory;         item2.icon = getresources().getdrawable(r.drawable.favorite_full);         item2.label = category;         slidemenu.addmenuitem(item2);     } } 

Comments

Popular posts from this blog

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

keyboard - Smiles and long press feature in Android -

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