android - Row color based on contents in the ListView of my RSS reader -


i android newbie , have built simple rss reader application based around free ibm android rss tutorial. change background color of each row if category of row equal particular string.

i wrote following "for loop" discovers category of each item , runs if statement should category equal "news". @ moment background colour of entire listview gets changed feed supplied news category.

does out there feel helping out beginner?

for(int = 0; < feed.getitemcount(); i++) {     if (feed.getitem(i).getcategory().equals("news"))     {        listview.setbackgroundcolor(0x77ee0044);     } } 

you're going need inside getview() method of adapter.

before return view in getview(), can call setbackgroundcolor() on view or use 1 of other setbackgroundfoo() methods.

edit - given code, when create adapter, try:

arrayadapter<rssitem> adapter = new arrayadapter<rssitem>(   this,android.r.layout.simple_list_item_1,feed.getallitems(­)) {     @override     public view getview(int position, view convertview, viewgroup parent) {         view view = super.getview(position, convertview, parent);         if (getitem(position).getcategory().equals("news")) {             view.setbackgroundcolor(0xffff0000); // red         }         return view;     } }; 

this overrides getview() adjust background of list item views properly.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -