android - list item select set bgcolor but scroll down automatically list item set bgcolor changed -


particular list item select set bgcolor list item ,when scroll down listview automatically set color other item, sample code suggestion , me.(this code v.setbackgroundcolor(color.gray) using problem occur,so clear problem)

public class mainactivity extends activity {     listview list; arrayadapter<string> adapter; arraylist<string>listitem=new arraylist<string>(); string val; string[] list_number={"1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25"}; @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);      list=(listview)findviewbyid(r.id.listview1);     adapter=new arrayadapter<string>(this,android.r.layout.simple_list_item_1,list_number);     list.setadapter(adapter);       list.setonitemclicklistener(new onitemclicklistener() {             @override             public void onitemclick(adapterview<?> parent, view v, int position,                     long id) {                    string selectedfromlist =(list.getitematposition(position).tostring());                                   if(listitem.isempty())                 {                     listitem.add(selectedfromlist);                     set<string> primeswithoutduplicates = new linkedhashset<string>(listitem);                     listitem.clear();                                       listitem.addall(primeswithoutduplicates);                     v.setbackgroundcolor(color.gray);                     }                 else                 {                         if( listitem.contains(selectedfromlist))                         {                             listitem.remove(selectedfromlist);                              v.setbackgroundcolor(color.white);                     }                         else                          {                             listitem.add(selectedfromlist);                                                                         set<string> primeswithoutduplicates = new linkedhashset<string>(listitem);                             listitem.clear();                                               listitem.addall(primeswithoutduplicates);                             v.setbackgroundcolor(color.gray);                         }                                                                        }                            }         });      } } 


Comments