android - Swipeable Recycler View listener overriden by view pager's -
i using this library (swipeablerecyclerview)
the cardview when swiped moves little distance , fragment starts moving.
i.e. point recyclerview listener implemented library's callback works , viewpager's swipe comes action.
is there someway of overcoming situation? have 2 fragments, want like:
right swipe - recyclerview listener called , cardview dismissed left swipe - viewpager scroll called , fragments swiped.
code:
swipeablerecyclerviewtouchlistener swipetouchlistener = new swipeablerecyclerviewtouchlistener(rv, new swipeablerecyclerviewtouchlistener.swipelistener() { @override public boolean canswipe(int position) { return true; } @override public void ondismissedbyswipeleft(recyclerview recyclerview, int[] reversesortedpositions) { (int position : reversesortedpositions) { messages.remove(numbers.get(position)); numbers.remove(position); adapter.notifyitemremoved(position); } adapter.notifydatasetchanged(); } @override public void ondismissedbyswiperight(recyclerview recyclerview, int[] reversesortedpositions) { (int position : reversesortedpositions) { messages.remove(numbers.get(position)); numbers.remove(position); adapter.notifyitemremoved(position); } adapter.notifydatasetchanged(); } }); rv.addonitemtouchlistener(swipetouchlistener);
answering own question. shared commonsware, created custom view pager faced reverse problem (viewpager won't swipe , cards would).
so made more tweaks custom viewpager :
public class myviewpager extends viewpager { public myviewpager(context context, attributeset attrs) { super(context, attrs); } @override protected boolean canscroll(view v, boolean checkv, int dx, int x, int y) { if (v instanceof myrecyclerview) { if(dx>0) return(super.canscroll(v, checkv, dx, x, y)); else return(true); } return(super.canscroll(v, checkv, dx, x, y)); } }
myreceyclerview custom recyclerview being used in 1 fragment. dx>0 ensures if im coming right frag left 1 viewpager listener called else cards swiped away (deleted) left right.
outcome: viewpager working intended, simultaneously cards being swiped/dismissed users. commonsware.
Comments
Post a Comment