android - how to bind a RecyclerView item and its containing button clicked event together -


i have recyclerview , items contain button. , wanna recyclerview item position when click on button. here problem, when button clicked button clicked event triggered recyclerview item under neath not, clicked event can not go through button on top recyclerview item. how can click-through event or how can bind them together? please tell me if know answer.

update: not find similar post online. recyclerview contains button register different onclickedlistener. in case, need handle same listener, particularly recyclerview handle it. button block clicked event of recyclerview. here viewholder code: `public class gridviewadapter extends recyclerview.adapter {

    private final linkedlist<device> mvalues;     private final onlistfragmentinteractionlistener mlistener;     private onlongclicklistener monlongclicklistener = null;      public gridviewadapter(linkedlist<device> items, onlistfragmentinteractionlistener listener) {         mvalues = items;         mlistener = listener;     }      @override     public viewholder oncreateviewholder(viewgroup parent, int viewtype) {         view view = layoutinflater.from(parent.getcontext())                 .inflate(r.layout.device, parent, false);         return new viewholder(view);     }      @override     public void onbindviewholder(final viewholder holder, int position) {         holder.mitem = mvalues.get(position); //        holder.miconview.setimageresource(r.drawable.ic_switch);          holder.mnameview.settext(holder.mitem.device_name());          holder.mview.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view v) {                 if (null != mlistener) {                     mlistener.ondeviceclicked(holder.mitem);                 }             }         });     }      public void deletebydevicecode(int devicecode) {         for(int i=0;i<mvalues.size();i++) {             if (mvalues.get(i).device_code() == devicecode) {                 mvalues.remove(i);             }         }     }      public void deletebyposition(int pos) {         mvalues.remove(pos);     }      public int getdevicecodebyposition(int pos) {         return mvalues.get(pos).device_code();     }      @override     public int getitemcount() {         return mvalues.size();     }      public class viewholder extends recyclerview.viewholder {         public final view mview;         public final button mbutton;         public final textview mnameview;         public device mitem;          public viewholder(view view) {             super(view);             mview = view;             mbutton = (button) view.findviewbyid(r.id.dev_button);             mnameview = (textview) view.findviewbyid(r.id.dev_lable);         }          @override         public string tostring() {             return super.tostring() + " '" + mnameview.gettext() + "'";         }      } }` 

when creating view holders, try passing them index of element represented them, or reference whole element. now, when you've receiving click event in view holder, event should pass (index of) element represented holder/row.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

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

asp.net - Problems sending emails from forum -