android - Adapter not working properly until scrolled -


in listview want have textviews image drawables colored accordingly text. tried using code below while text showing expected, drawable shows last color in list of textviews - until list scrolled, shows right color.

 @override public view getview(final int position, view convertview, viewgroup parent) {     viewholder holder;     layoutinflater inflater = (layoutinflater) context.getsystemservice(context.layout_inflater_service);     view row = convertview;     if (row == null) {         row = inflater.inflate(r.layout.mylayout, parent, false);         holder = new viewholder();         holder.textview = (textview) row.findviewbyid(r.id.mytextview);         holder.img = getresources().getdrawable(r.drawable.my_icon);         row.settag(holder);     } else {         holder = (viewholder) row.gettag();     }      holder.textview.settext(colors[position]);      int color = 0;     switch (colors[position])     {         case "blue":             color = getresources().getcolor(r.color.blue);             break;         case "green":             color = getresources().getcolor(r.color.green);             break;         case "red":             color = getresources().getcolor(r.color.red);             break;     }      holder.img.setcolorfilter(color, porterduff.mode.src_atop);     holder.textview.setcompounddrawableswithintrinsicbounds(null, null, null, holder.img);     return row; } static class viewholder {     textview textview;     drawable img; } 

why trying point holder.img drawable image. should use view , setbackgroundcolour it


Comments

Popular posts from this blog

matlab - error with cyclic autocorrelation function -

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

c# - What is a good .Net RefEdit control to use with ExcelDna? -