gridview - Android OnClickListener does not get fired when clicked on first image in the grid -


i have fragment has grid view displaying upto 5 images. onclicklistener not fired first image in grid works when clicked on other images in grid.

public view getview(int position, view convertview, viewgroup parent) {     imageview imageview;     if (convertview == null) {         imageview = new imageview(_activity);     } else {         imageview = (imageview) convertview;     }      string imageurls = _filepaths.get(position).tostring();     picasso.with(this._activity).load(imageurls).placeholder(r.mipmap.ic_launcher).into(imageview);      imageview.setscaletype(imageview.scaletype.center_crop);     imageview.setlayoutparams(new gridview.layoutparams(imagewidth,             imagewidth));      imageview.setonclicklistener(new onimageclicklistener(position));      return imageview; }  class onimageclicklistener implements onclicklistener {      int _postion;      // constructor     public onimageclicklistener(int position) {         this._postion = position;     }      @override     public void onclick(view v) {         intent = new intent(_activity, fullscreenviewactivity.class);         i.putextra("position", _postion);         i.putextra("paths", _filepaths);         _activity.startactivity(i);     }  } 

you should try setting position tag of imageview in getview() method , getting tag(position) in onclick() method.

public view getview(int position, view convertview, viewgroup parent) {     imageview imageview;     if (convertview == null) {         imageview = new imageview(_activity);     } else {         imageview = (imageview) convertview;     }      string imageurls = _filepaths.get(position).tostring();     picasso.with(this._activity).load(imageurls).placeholder(r.mipmap.ic_launcher).into(imageview);      imageview.setscaletype(imageview.scaletype.center_crop);     imageview.setlayoutparams(new gridview.layoutparams(imagewidth,             imagewidth));      imageview.settag(position);     imageview.setonclicklistener(this);      return imageview; }    @override public void onclick(view v) {     intent = new intent(_activity, fullscreenviewactivity.class);     i.putextra("position", v.gettag()+"");     i.putextra("paths", _filepaths);     _activity.startactivity(i);     }  } 

also don't forget implement view.onclicklistener


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -