android - best way to get RecycleView detail in another view -


i'm implementing onclick on main layout contain views, in order pass data view e.g:

 holder.wholeview.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view view) {             toast.maketext(mcontext, string.valueof(position), toast.length_short).show();          //pass data eventbus , transition view          }     }); 

i think there better way that?

use this:

public class recyclertouchlistener implements recyclerview.onitemtouchlistener {      public interface clicklistener {         void onclick(view view, int position);          void onlongclick(view view, int position);     }      private gesturedetector gesturedetector;     private clicklistener clicklistener;      public recyclertouchlistener(context context, final recyclerview recyclerview, final clicklistener clicklistener) {         this.clicklistener = clicklistener;         gesturedetector = new gesturedetector(context, new gesturedetector.simpleongesturelistener() {             @override             public boolean onsingletapup(motionevent e) {                 return true;             }              @override             public void onlongpress(motionevent e) {                 view child = recyclerview.findchildviewunder(e.getx(), e.gety());                 if (child != null && clicklistener != null) {                     clicklistener.onlongclick(child, recyclerview.getchildposition(child));                 }             }         });     }      @override     public boolean onintercepttouchevent(recyclerview rv, motionevent e) {          view child = rv.findchildviewunder(e.getx(), e.gety());         if (child != null && clicklistener != null && gesturedetector.ontouchevent(e)) {             clicklistener.onclick(child, rv.getchildposition(child));         }         return false;     }      @override     public void ontouchevent(recyclerview rv, motionevent e) {     }      @override     public void onrequestdisallowintercepttouchevent(boolean disallowintercept) {      }  } 

and activity you're using recycler view use this:

mrecyclerview.addonitemtouchlistener(new recyclertouchlistener(this, mrecyclerview,                 new recyclertouchlistener.clicklistener() {                     @override                     public void onclick(view view, int position) {                     // use position fetch data list used populate recylcer view                     }                      @override                     public void onlongclick(view view, int position) {                      }                 })); 

Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -