android - How to add Recycler item SetOnClickListener in javatechig example -


i'm trying add onclicklistener recyclerview tryied , doesnt work!:

feeditem:

public class feeditem {     private string title;     private string thumbnail;     private string date;     private string tags;      public string gettitle() {         return title;     }      public void settitle(string title) {         this.title = title;     }      public string getthumbnail() {         return thumbnail;     }      public void setthumbnail(string thumbnail) {         this.thumbnail = thumbnail;     }      public string getdate() {         return date;     }      public void getdate(string date) {         this.date = date;     }      public string gettags() {         return tags;     }      public void settags(string tags) {         this.tags = tags;     }  } 

feedlistrowholder:

public class feedlistrowholder extends recyclerview.viewholder {     protected imageview thumbnail;     protected textview title;     protected textview date;     protected textview tags;      public feedlistrowholder(view view) {         super(view);         this.thumbnail = (imageview) view.findviewbyid(r.id.thumbnail);         this.title = (textview) view.findviewbyid(r.id.title);         this.date = (textview) view.findviewbyid(r.id.date);         this.tags = (textview) view.findviewbyid(r.id.tagsitems);     }  } 

adapter:

public class myrecycleradapter extends recyclerview.adapter<feedlistrowholder> {      private list<feeditem> feeditemlist;     private context mcontext;      public myrecycleradapter(context context, list<feeditem> feeditemlist) {         this.feeditemlist = feeditemlist;         this.mcontext = context;     }      @override     public feedlistrowholder oncreateviewholder(viewgroup viewgroup, int i) {         view v = layoutinflater.from(viewgroup.getcontext()).inflate(r.layout.list_row, null);         return new feedlistrowholder(v);     }      @override     public void onbindviewholder(feedlistrowholder feedlistrowholder, int i) {         feeditem feeditem = feeditemlist.get(i);         picasso.with(mcontext).load(feeditem.getthumbnail())                 .error(r.drawable.placeholder)                 .placeholder(r.drawable.placeholder)                 .into(feedlistrowholder.thumbnail);          feedlistrowholder.title.settext(html.fromhtml(feeditem.gettitle()));         feedlistrowholder.date.settext(html.fromhtml(feeditem.getdate()));         feedlistrowholder.tags.settext(html.fromhtml(feeditem.gettags()));     }      @override     public int getitemcount() {         return (null != feeditemlist ? feeditemlist.size() : 0);     } } 

how can add onclicklistener recyclerview?

thanks

write on oncreate method

 recyclerview.addonitemtouchlistener(                     new recycleritemclicklistener(getactivity(), new recycleritemclicklistener.onitemclicklistener() {                         @override                         public void onitemclick(view view, int position) {                             feeditem bookscreendateentity = (feeditem)yourlist.get(position);                              bookscreendateentity.getserviceid();                          }                     })             ); 

recycleritemclicklistener class:

public class recycleritemclicklistener implements recyclerview.onitemtouchlistener {         private onitemclicklistener mlistener;          public interface onitemclicklistener {             public void onitemclick(view view, int position);         }          gesturedetector mgesturedetector;          public recycleritemclicklistener(context context, onitemclicklistener listener) {             mlistener = listener;             mgesturedetector = new gesturedetector(context, new gesturedetector.simpleongesturelistener() {                 @override                 public boolean onsingletapup(motionevent e) {                     return true;                 }             });         }          @override         public boolean onintercepttouchevent(recyclerview view, motionevent e) {              view childview = view.findchildviewunder(e.getx(), e.gety());             if (childview != null && mlistener != null && mgesturedetector.ontouchevent(e)) {                 mlistener.onitemclick(childview, view.getchildadapterposition(childview));                 return true;             }             return false;         }          @override         public void ontouchevent(recyclerview view, motionevent motionevent) {         }          @override         public void onrequestdisallowintercepttouchevent(boolean disallowintercept) {         }     } 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -