android - touch listener takes precedence over listscroll listener -


i have got horizontal list swipe dismiss working except swipe dismiss takes precendence on scrolling ie if swipe left right on slightest angle think im trying swipe dismiss item instead of scrolling list along. think easiest approach have other way around have no idea how change or if there better way

i've modified lucas rocha's twowayview , roman nurik/tim roes swipedismissundolist

i'm not sure if code should looking can tell it's relevant.

mainactivity

   listview = (twowayview) findviewbyid(r.id.listview1);       //need add in emptyview , list view show , gone them when emtpy/full      imageadapter = new imageadapter(this, products,emptyview,listview);       listview.setadapter(imageadapter);       vswipedismisslist.ondismisscallback callback = new vswipedismisslist.ondismisscallback() {         @override         public vswipedismisslist.undoable ondismiss(abslistview listview, final int position) {             // delete item adapter (sample code):              imageadapter.remove(position);             return null;              }      }; 

swipedismiss

/**  * returns {@link android.widget.abslistview.onscrolllistener}  * added {@link listview} using  * {@link listview#setonscrolllistener(android.widget.abslistview.onscrolllistener)}.  * if scroll listener assigned, caller should still pass  * scroll changes through listener. ensure  * {@link swipedismisslistviewtouchlistener} paused during list view  * scrolling.</p>  *  * @see {@link swipedismisslistviewtouchlistener}  */ private abslistview.onscrolllistener makescrolllistener() {     return new abslistview.onscrolllistener() {         @override         public void onscrollstatechanged(abslistview abslistview, int scrollstate) {             setenabled(scrollstate != abslistview.onscrolllistener.scroll_state_touch_scroll);         }          @override         public void onscroll(abslistview abslistview, int i, int i1, int i2) {         }     }; }  @override public boolean ontouch(view view, motionevent motionevent) {... 

twowayview

    private boolean maybestartscrolling(int delta) {     final boolean isoverscroll = (moverscroll != 0);     if (math.abs(delta) <= mtouchslop && !isoverscroll) {         return false;     }      if (isoverscroll) {         mtouchmode = touch_mode_overscroll;     } else {         mtouchmode = touch_mode_dragging;     }      // time start stealing events! once we've stolen them, don't     // let steal us.     final viewparent parent = getparent();     if (parent != null) {         parent.requestdisallowintercepttouchevent(true);     }      cancelcheckforlongpress();      setpressed(false);     view motionview = getchildat(mmotionposition - mfirstposition);     if (motionview != null) {         motionview.setpressed(false);     }      reportscrollstatechange(onscrolllistener.scroll_state_touch_scroll);      return true; }  private void maybescroll(int delta) {     if (mtouchmode == touch_mode_dragging) {         handledragchange(delta);     } else if (mtouchmode == touch_mode_overscroll) {         handleoverscrollchange(delta);     } }  private void handledragchange(int delta) {     // time start stealing events! once we've stolen them, don't     // let steal us.     final viewparent parent = getparent();     if (parent != null) {         parent.requestdisallowintercepttouchevent(true);     }      final int motionindex;     if (mmotionposition >= 0) {         motionindex = mmotionposition - mfirstposition;     } else {         // if don't have motion position can reliably track,         // pick in middle make best guess @ things below.         motionindex = getchildcount() / 2;     }      int motionviewprevstart = 0;     view motionview = this.getchildat(motionindex);     if (motionview != null) {         motionviewprevstart = (misvertical ? motionview.gettop() : motionview.getleft());     }      boolean atedge = scrolllistitemsby(delta);      motionview = this.getchildat(motionindex);     if (motionview != null) {         final int motionviewrealstart =                 (misvertical ? motionview.gettop() : motionview.getleft());          if (atedge) {             final int overscroll = -delta - (motionviewrealstart - motionviewprevstart);             updateoverscrollstate(delta, overscroll);         }     } } 

i found pretty duplicate question here

i added action down , action move code ontouch method of swipedismiss

     @override    public boolean onintercepttouchevent(motionevent ev) {     switch (ev.getaction()) {     case motionevent.action_down:         xdistance = ydistance = 0f;         lastx = ev.getx();         lasty = ev.gety();         break;     case motionevent.action_move:         final float curx = ev.getx();         final float cury = ev.gety();         xdistance += math.abs(curx - lastx);         ydistance += math.abs(cury - lasty);         lastx = curx;         lasty = cury;         if(xdistance > ydistance)             return false; } 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -