android - onItemClickListener implemented on other rows of custom ListView -
--edited--
what have:
2 listviews of different colors
i using customlistviewadapter
what want do:
1-on item click of first listview, color of view set same color of second , textview's text color white instead of black.
2-when clicking item, first item return was.
problem:
everything went great till noticed when click item , scrolling, other views changing background color , text color too..
in getview() in customlistadapater:
code:
vi = inflater.inflate(r.layout.itemshow, null); vi.setonclicklistener(new onclicklistener(){ @override public void onclick(view v) { log.i("mylist","isclicked"); if(previousview!=null){ previousview.setbackgroundcolor(color.white); holder.nametext.settextcolor(color.black); holder.quantitytext.settextcolor(color.black); holder.pricetext.settextcolor(color.black); } v.setbackgroundcolor(color.parsecolor("#330000")); holder.nametext.settextcolor(color.white); holder.quantitytext.settextcolor(color.white); holder.pricetext.settextcolor(color.white); previousview = v; } });
thanks in advance help...
you need set default color views in getview
method of listviews
. reason happens because views recycled in listview
. if want have more control of views better create own adapter , override getview()
method:
@override public view getview(int position, view convertview, viewgroup parent) { vi = inflater.inflate(r.layout.itemshow, null); vi.setonclicklistener(new onclicklistener(){ @override public void onclick(view v) { log.i("mylist","isclicked"); if(previousview!=null){ previousview.setbackgroundcolor(color.white); holder.nametext.settextcolor(color.black); holder.quantitytext.settextcolor(color.black); holder.pricetext.settextcolor(color.black); } vi.setbackgroundcolor(color.parsecolor("#330000")); holder.nametext.settextcolor(color.white); holder.quantitytext.settextcolor(color.white); holder.pricetext.settextcolor(color.white); previousview = vi; } }); vi.setbackgroundcolor(color.parsecolor("#000000")); // setup default color here // textview's well, if change them on click }
Comments
Post a Comment