java - create slide show with button bar -
i want make main activity changing ground swipping image , and on left side want put button bar contain 4 buttons move 4 different activities write folloning code :
public class mainactivity extends activity { button[] buttons = new button[4]; sharedpreferences fsc; private static final int swipe_min_distance = 120; private static final int swipe_threshold_velocity = 200; private viewflipper mviewflipper; private context mcontext; private final gesturedetector detector = new swipegesturedetector(); @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); getwindow().setflags(windowmanager.layoutparams.flag_fullscreen, windowmanager.layoutparams.flag_fullscreen); setcontentview(r.layout.activity_main); setrequestedorientation(activityinfo.screen_orientation_portrait); addlisteneronbutton(); setcontentview(r.layout.activity_main); mcontext = this; mviewflipper = (viewflipper) this.findviewbyid(r.id.view_flipper); mviewflipper.setontouchlistener(new ontouchlistener() { @override public boolean ontouch(final view view, final motionevent event) { detector.ontouchevent(event); return true; } }); } private void addlisteneronbutton() { buttons[0] = (button) findviewbyid(r.id.slide); buttons[0].setonclicklistener(new onclicklistener() { public void onclick(view arg0) { intent myintent = new intent(mainactivity.this, slideshow.class); startactivity(myintent); // todo auto-generated method stub } } ); class swipegesturedetector extends simpleongesturelistener { @override public boolean onfling(motionevent e1, motionevent e2, float velocityx, float velocityy) { try { // right left swipe if (e1.getx() - e2.getx() > swipe_min_distance && math.abs(velocityx) > swipe_threshold_velocity) { mviewflipper.setinanimation(animationutils.loadanimation(mcontext, r.anim.left_in)); mviewflipper.setoutanimation(animationutils.loadanimation(mcontext, r.anim.left_out)); mviewflipper.shownext(); return true; } else if (e2.getx() - e1.getx() > swipe_min_distance && math.abs(velocityx) > swipe_threshold_velocity) { mviewflipper.setinanimation(animationutils.loadanimation(mcontext, r.anim.right_in)); mviewflipper.setoutanimation(animationutils.loadanimation(mcontext,r.anim.right_out)); mviewflipper.showprevious(); return true; } } catch (exception e) { e.printstacktrace(); } return false; } }
}
you aren't import
ing library classes need. this question may helpful.
it looks you're doing hand in basic text editor. using ide eclipse (which has android tools) keep having hand.
Comments
Post a Comment