android - swipe between activities,swipe from one activity to another -
i trying swipe activity failed so. below code doing nothing, not giving error. don't know do.
final view lay_first=(view) findviewbyid(r.id.lay_first); lay_first.setontouchlistener(new onswipetouchlistener(){ @override public boolean onswipeleft() { intent intent=new intent(slidewindow.this,mainactivity.class); startactivity(intent); overridependingtransition(r.anim.right_to_left, r.anim.rl2); return true; } @override public boolean onswiperight() { intent intent=new intent(slidewindow.this,mainactivity.class); startactivity(intent); overridependingtransition(r.anim.right_to_left, r.anim.rl2); return true; } @override public boolean onswipebottom() { super.onswipebottom(); return true; } @override public boolean onswipetop() { super.onswipetop(); return true; } }); } public class onswipetouchlistener implements ontouchlistener{ @suppresswarnings("deprecation") gesturedetector gesturedetector=new gesturedetector(new gesturelistener()); @override public boolean ontouch(view v, motionevent event) { if(gesturedetector.ontouchevent(event)) { return true; } return false; } private final class gesturelistener extends simpleongesturelistener{ private static final int swipe_threshold = 100; private static final int swipe_velocity_threshold = 100; @override public boolean ondown(motionevent e) { return super.ondown(e); } @override public boolean onfling(motionevent e1, motionevent e2, float velocityx, float velocityy) { boolean result=false; try { float diffy=e2.gety()-e1.gety(); float diffx=e2.getx()-e1.getx(); if(math.abs(diffx)>math.abs(diffy)) { if(math.abs(diffx)>swipe_threshold && math.abs(velocityx)>swipe_velocity_threshold) { if(diffx>0) { result=onswiperight(); } else { result=onswipeleft(); } } } else { if(math.abs(diffy)>swipe_threshold && math.abs(velocityy)>swipe_velocity_threshold) { if(diffy>0) { result=onswipebottom(); } else { result=onswipetop(); } } } }catch(exception e) { e.printstacktrace(); } return result; } } public boolean onswiperight() { return false; } public boolean onswipeleft() { return false; } public boolean onswipebottom() { return false; } public boolean onswipetop() { return false; } }}
but when doing slide on touchevent running.but when adding gestures not,as gesturedetector class depriciated reason program not running.
take @ this, official tutorial http://android-developers.blogspot.com/2011/08/horizontal-view-swiping-with-viewpager.html
Comments
Post a Comment