How to create add colors to listview in android? -


i working on listview in android , want alternate colors listview?

my code:

string listview_array[] = { "1. test1", "2. test2" }  public void oncreate(bundle icicle) {     super.oncreate(icicle);     setcontentview(r.layout.main);     lv = (listview) findviewbyid(r.id.listview);      lv.setadapter(new arrayadapter<string>(this,             r.layout.listview_header_row, listview_array));     lv.settextfilterenabled(true); } 

any suggestions?

use custom adapter this

public class mysimplearrayadapter extends arrayadapter<string> {   private final context context;   private final string[] values;    public mysimplearrayadapter(context context, string[] values) {     super(context, r.layout.rowlayout, values);     this.context = context;     this.values = values;   }    @override   public view getview(int position, view convertview, viewgroup parent) {     layoutinflater inflater = (layoutinflater) context         .getsystemservice(context.layout_inflater_service);     view rowview = inflater.inflate(r.layout.rowlayout, parent, false);      //do assigning here change color      if ((position%2)==0) {       rowview.setbackgroundcolor(r.color.first);     } else {       rowview.setimageresource(r.color.second);     }      return rowview;   } }  

for more custom adapter see this


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -