Tuesday, 15 May 2012

java - two Different color for saparate list in android -



java - two Different color for saparate list in android -

i have 3 arraylist, i.e a, b, c. merged arraylist , arraylist b arraylist c (empty). able display elements both , b. problem want dispaly elements in greenish color , elements b in greay color. code this

private class mylistadapter extends baseadapter{ layoutinflater minflator; boolean flag; boolean flag1; public mylistadapter(arraylist<bluetoothdevice> alist) { // todo auto-generated constructor stub super(); minflator = trackdevices.this.getlayoutinflater(null); carraylist = alist; flag = carraylist.addall(aarraylist); flag1 = carraylist.addall(barraylist); } @override public view getview(int position, view view, viewgroup parent) { viewholder holder = new viewholder(); // todo auto-generated method stub if(view == null){ view = minflator.inflate(r.layout.track_frag, null); holder.devicetag = (textview)view.findviewbyid(r.id.track); if(flag){ view.setbackgroundcolor(color.green); }else if(flag1){ view.setbackgroundcolor(color.gray); } view.settag(holder); }else{ holder = (viewholder)view.gettag(); } bluetoothdevice device = carraylist.get(position); final string devicename = device.getaddress(); if (devicename != null && devicename.length() > 0){ holder.devicetag.settext(devicename); }else{ holder.devicetag.settext("no devices"); } homecoming view; } }

above code showing in greenish color both , b elements in c arraylist. how create different each list.

use size property of arrylist,

int flag=a.size();

and in getview method this:-

if(position<flag) { view.setbackgroundcolor(color.green); } else { view.setbackgroundcolor(color.gray); }

java android android-listview arraylist adapter

No comments:

Post a Comment