android - get the start moveing int and the end moving int in recyclerview the same -
i had strange problem recyclerview , ontouchlistener, i'm trying move items of recyclerview through itemtouchhelper.callback callbacks (onmove, clearview), problem in ontouchlistener when trying place of action_down in order correct viewitem moved , place of action_up in order place move to, got same position number when trying move bigger position small position , movement doesn't happen, unlike when try move small position bigger position works correctly , items moved without no problem. here code on touch
recyclerview.setontouchlistener(new view.ontouchlistener() { @override public boolean ontouch(view v, motionevent event) { switch (event.getaction()) { case action_move: if(first==0) { start=recyclerview.getchildviewholder(recyclerview.findchildviewunder(event.getx(), event.gety())).getadapterposition(); log.e("filter1 start",start+""); first=1; } else { end = recyclerview.getchildviewholder(recyclerview.findchildviewunder(event.getx(), event.gety())).getadapterposition(); log.e("filter1 end",end+""); } } return false; } });
and here code move items callback function
@override public void itemtouchonmove(int oldposition, int newposition) { list.add(newposition,list.remove(oldposition)); adapter.notifyitemmoved(oldposition,newposition); adapter.notifydatasetchanged(); }
and here callback class
public class myitemtouchhelpercallback extends itemtouchhelper.callback { callbackitemtouch callbackitemtouch; // interface public myitemtouchhelpercallback(callbackitemtouch callbackitemtouch){ this.callbackitemtouch = callbackitemtouch; } @override public boolean islongpressdragenabled() { return true; } @override public boolean isitemviewswipeenabled() { return true; // swiped disabled } @override public int getmovementflags(recyclerview recyclerview, recyclerview.viewholder viewholder) { int dragflags = itemtouchhelper.right|itemtouchhelper.left|itemtouchhelper.up | itemtouchhelper.down|itemtouchhelper.action_state_drag|itemtouchhelper.action_state_swipe; // movements drag return makeflag( itemtouchhelper.action_state_drag , dragflags); // parameter, action drag , flags drag } @override public boolean onmove(recyclerview recyclerview, recyclerview.viewholder viewholder, recyclerview.viewholder target) { return true; } @override public void onswiped(recyclerview.viewholder viewholder, int direction) { // swiped disabled } @override public void clearview(recyclerview recyclerview, recyclerview.viewholder viewholder) { super.clearview(recyclerview, viewholder); if(start!=end && start!=-1 && end!=-1) { callbackitemtouch.itemtouchonmove(start, end); first=0; } }
}
for example simplify problem when try move 1 pos 5 pos got start=1 , end=5 , move happen when try move item 10 8 got start=10 , end=10 , make movement doesn't happen although dragged item in 8 position doesn't sense this.
Comments
Post a Comment