android - How click Next Button and Back Button in array index -
i'm creating app on android viewing image when select next button show new image , button show previous image when press next button maximum index , want show start first image index , when press button minimum index, want show start maxminum image index. have problem when click button go 0 index want show image final index , when click next button go final index want show 0 index. *
if (v == btn_back) { if((currentimageindex)!=0){ imageview.setimageresource(image_ids[currentimageindex]); mp = mediaplayer.create(this, mymusic[currentsoundindex]); mp.start(); --currentimageindex; --currentsoundindex; } if((currentimageindex)==0){ imageview.setimageresource(image_ids[currentimageindex]); mp = mediaplayer.create(this, mymusic[currentsoundindex]); mp.start(); --currentimageindex; --currentsoundindex;} if(v== btn next){*******}
replace --currentimageindex with:
currentimageindex = (currentimageindex + image_ids.length -1) % image_ids.length; when index 0 make wrap around image_ids.length-1.
note, going forward need this:
currentimageindex = (currentimageindex + 1) % image_ids.length;
Comments
Post a Comment