android - Custom listview background color change at runtime -



android - Custom listview background color change at runtime -

i have application custom list view has textview , imageview. when click image view, background color should change. tried this, getting nullpointerexception ...here code

customlistviewadapter.java

public class viewholder { textview mname; imageview mdeleteimage; } public view getview(int position, view convertview, viewgroup parent) { holder = null; datafields rowitems = (datafields) getitem(position); layoutinflater inflater = (layoutinflater) context .getsystemservice(activity.layout_inflater_service); if (convertview == null) { convertview = inflater.inflate(r.layout.home_field_row, null); holder = new viewholder(); holder.mname = (textview) convertview.findviewbyid(r.id.hmfieldname); holder.mdeleteimage = (imageview)convertview.findviewbyid(r.id.hmfielddeleteimage); convertview.settag(holder); holder.mdeleteimage.settag(position); holder.mdeleteimage.setonclicklistener(new imageview.onclicklistener() { @override public void onclick(final view view) { count++; mlistrowrl = (relativelayout)view.findviewbyid(r.id.hmfieldmainrl); mlistrowrl.setbackgroundcolor(color.list_row_bg); //throwing nullpointerexception } }); } else { holder = (viewholder) convertview.gettag(); } holder.mname.settext(rowitems.getname()); homecoming convertview; }

any kind of suggestion much appreciated. !

holder.mdeleteimage.setonclicklistener(new imageview.onclicklistener() { @override public void onclick(final view view) { count++; mlistrowrl = (relativelayout)view.findviewbyid(r.id.hmfieldmainrl); mlistrowrl.setbackgroundcolor(color.list_row_bg); //throwing nullpointerexception } });

you assigning click listener imageview fine.. in onclick method trying search view passed in (which imageview) row.. imageviews not contain kid views mlistrowrl null. seek this

final view clickview = convertview; holder.mdeleteimage.setonclicklistener(new imageview.onclicklistener() { @override public void onclick(final view view) { count++; clickview.setbackgroundcolor(color.list_row_bg); } });

android android-listview

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -