Android custom ArrayAdapter not staying on scroll -


i have created custom arrayadapter (code below) works fine until scroll. once scroll items go green , have been pulling hair trying figure out why. appreciated.

the custom adapter intended make text of listview item 3 characters long turn green while others should remain default color of black.

public class foundadapter extends arrayadapter<string> {    private final activity context;   private final arraylist<string> names;    static class viewholder {     public textview text;   }    public foundadapter(activity context, arraylist<string> names) {     super(context, r.layout.found, names);     this.context = context;     this.names = names;   }    @override   public view getview(int position, view convertview, viewgroup parent) {     view rowview = convertview;     if (rowview == null) {       layoutinflater inflater = context.getlayoutinflater();       rowview = inflater.inflate(r.layout.found, null);       viewholder viewholder = new viewholder();       viewholder.text = (textview) rowview.findviewbyid(r.id.found_txt);       rowview.settag(viewholder);     }      viewholder holder = (viewholder) rowview.gettag();     string s = names.get(position);     if(s.length()==3) {         holder.text.settextcolor(0xff008b45); //green     }     holder.text.settext(s);      return rowview;   } }  

called in .java code via:

adapter=new foundadapter(this, array);       listview view = (listview) findviewbyid(r.id.list); view.setadapter(adapter); 

r.layout.found:

<?xml version="1.0" encoding="utf-8"?>  <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal">  <textview      android:id="@+id/found_txt"   android:layout_width="wrap_content"   android:layout_height="wrap_content"   android:gravity="center"     android:textsize="20sp"      /> </linearlayout> 

the problem not resetting text color if condition not satisfy. in listviews views recycled.

so this

if(s.length()==3) {     holder.text.settextcolor(0xff008b45); //green }else{     holder.text.settextcolor(xyz); //xyz } 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -