android - CoordinatorLayout with RecyclerView: onScroll -


i have recyclerview have added different actions can performed on list items. particularly, dragdrop , swipedismiss. dragdrop initiated long-press, , swipedismiss initiated swiping. have watch scroll events block actions happening. annoying scrolling switched dragging. before add onscrolllistener handle this.

this did before:

@override public void onscrollstatechanged(recyclerview recyclerview, int newstate) {     super.onscrollstatechanged(recyclerview, newstate);     if(newstate == recyclerview.scroll_state_idle){         drag.setcurrentaction(idle);     } else {         drag.setcurrentaction(scroll);     } } 

no longer work

i added coordinatorlayout collapsable toolbars. when scrolling up, drag wont set scroll until toolbar has been collapsed. tried create own behavior, replace current behavior using; @string/appbar_scrolling_view_behavior. removed behaviors wanted toolbar , didn't work notify drag state.


what have tried:

@override public boolean onstartnestedscroll(coordinatorlayout cl, collapsingtoolbarlayout child, view directtargetchild,         view target, int nestedscrollaxes) {      if (nestedscrollaxes == viewcompat.scroll_axis_vertical) {         if (drag.getcurrentaction().ordinal() < scroll.ordinal()) {             /* no actions have started , scrolling. set new action */             drag.setcurrentaction(scroll);         }         return true;     }     return super.onstartnestedscroll(cl, child, directtargetchild, target, nestedscrollaxes); }  @override public void onstopnestedscroll(coordinatorlayout coordinatorlayout, collapsingtoolbarlayout child, view target) {     super.onstopnestedscroll(coordinatorlayout, child, target);     if (drag.getcurrentaction() == scroll) {         drag.setcurrentaction(invalid);     } } 

so question

how listen scroll changes on recycler view being intercepted coordinatorlayout? behavior correct way?

you should instead use itemtouchhelper detailed in this blog post.

it contains methods such as

  • onmove(recyclerview, viewholder, viewholder)
  • onswiped(viewholder, int)

which allow implement drag , drop swipe dismiss without writing custom behaviors or touch event handling.


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -