android - Set recycle view item at on click time -


i want show horizontal list show inactive image of services (like petrol pump,tyre).after click recycle view have change inactive images active image.i take images url service , download , set it. think not possible solution selector stated here

any should appreciated.

public class servicescategoryadapter extends recyclerview.adapter<servicescategoryadapter.viewholder> {        public servicescategoryadapter(context context, arraylist<servicecategory> servicecategoryarraylist, googlemap googlemap, getvendorsservice getvendorsservice, latlng latlng, linearlayout subcategorylayout, recyclerview subcategoryrecycle) {         this.context = context;         this.servicecategoryarraylist = servicecategoryarraylist;         this.googlemap = googlemap;         mprefscmodel = context.getsharedpreferences(my_prefs_name, 0);         editor = mprefscmodel.edit();         this.getvendorsservice = getvendorsservice;         this.latlng = latlng;         this.subcategorylayout = subcategorylayout;         this.subcategoryrecycle = subcategoryrecycle;     }       sharedpreferences mprefscmodel;     private static sharedpreferences.editor editor;      @override     public servicescategoryadapter.viewholder oncreateviewholder(viewgroup parent, int viewtype) {         view itemlayoutview = layoutinflater.from(parent.getcontext()).inflate(r.layout.twowayview, null);          viewholder viewholder = new viewholder(itemlayoutview);         return viewholder;     }      @override     public void onbindviewholder(viewholder viewholder, int i) {           setimageview(viewholder.vehicleimage, servicecategoryarraylist.get(i).getinactiveimage(), i);         viewholder.servicecategoryname.settext(servicecategoryarraylist.get(i).getcategoryname());         viewholder.servicecategoryname.settextsize(8.0f);      }      @override     public int getitemcount() {         return servicecategoryarraylist.size();     }      // inner class hold reference each item of recyclerview     public static class viewholder extends recyclerview.viewholder {           public  static  imageview vehicleimage;         public textview servicecategoryname;         static   string image="";          public viewholder(view itemlayoutview) {             super(itemlayoutview);              vehicleimage = (imageview) itemlayoutview.findviewbyid(r.id.twowayviewimage);             servicecategoryname = (textview) itemlayoutview.findviewbyid(r.id.servicecategoryname);             itemlayoutview.setonclicklistener(new view.onclicklistener() {                 @override                 public void onclick(view v) {                     homefragment.isservicecategory = false;                     int position = getlayoutposition();                     viewholder viewholder = (viewholder) v.gettag();                       string servicecategoryid = servicecategoryarraylist.get(position).getcategoriesid();                     string servicecategoryname = servicecategoryarraylist.get(position).getcategoryname();                     getvendorsservice = new getvendorsservice(context, servicecategoryid, googlemap, servicecategoryname, latlng);                     getvendorsservice.execute();                     editor.putstring("servicecategoryid", servicecategoryid);                     editor.commit();                    image=servicecategoryarraylist.get(position).getimage();                      arraylist<servicecategory.subservicecategory> subservicecategoryobj = new arraylist<servicecategory.subservicecategory>();                     subservicecategoryobj = servicecategoryarraylist.get(position).getsubservicecategories();                     if (subservicecategoryobj.size() != 0) {                         subcategorylayout.setvisibility(view.visible);                         subcategoryadapter subcategoryadapter = new subcategoryadapter(context, subservicecategoryobj);                         subcategoryrecycle.setadapter(subcategoryadapter);                     }                     else                         subcategorylayout.setvisibility(view.gone);                  }             });          }      }      public static  void setimageview( imageview imageview, string url, int i) {          new imagedownloadservice(context, imageview).execute(url);       } } 

with above code able change image change last image not clicked. before click out put enter image description here

but after clicking second image pump service changes last image enter image description here

store boolean variable next data e.g. isclicked indicate if user has clicked on image, create image listener update boolean, , lastly in onbindviewholder test if/then statement , set correct picture based on isclicked variable current data.


Comments