did you mess with the GestureDetector stuff? it handles some of the determination of whether something is a scroll or fling, etc..
On Mon, May 23, 2011 at 11:39 PM, Spooky <spooky1...@gmail.com> wrote: > As determined as I was to solve this without having to ask > for help, I am now officially confused beyond all hope..... > > I've been digging, and digging, and diggin, through searches and > sample code, trying to find out how to change images (next or > previous) in an ImageView that displays one of many images at a > time with just a swipe of my finger, either to the left (next) or > right (previous). After finding a tutorial that appeared to do > close to what I was looking for, I adapted it, and came up with > the following (indentation trimmed for readability): > > > // NOTE: This is inside of the ImageView > > private float startx = 0; > private float endx = 0; > > public boolean onTouchEvent(MotionEvent event) { > switch (event.getAction()) { > case MotionEvent.ACTION_DOWN: > // Remember our initial down event location. > startx = event.getRawX(); > break; > case MotionEvent.ACTION_MOVE: > endx = event.getRawX(); > // Handle (next) > if (endx < startx) > mCurrentPhotoIndex = (mCurrentPhotoIndex + 1) > % mPhotoIds.length; > // Handle (prev) > if (endx > startx) { > mCurrentPhotoIndex = (mCurrentPhotoIndex - 1); > if (mCurrentPhotoIndex < 0) > mCurrentPhotoIndex = mPhotoIds.length - 1; > showPhoto(mCurrentPhotoIndex); > break; > } > } > return true; > } > > Obviously (well, it is NOW...), this resulted in each minute > touch of the screen advancing (or going backwards) by a seemingly > random number of images...as while I was still moving my finger > across the image, it was constantly seeing more movement, and > that triggered the MotionEvent again, and again, and again, and > again, and ... {ad nauseum}. So I started looking for a way to > tame this monster and get it under control. > > After reading more, and verifying something I thought I'd seen > (ACTION_UP), I arrived at this: > > // NOTE: This is inside of the ImageView > > private float startx = 0; > private float endx = 0; > > public boolean onTouchEvent(MotionEvent event) { > switch (event.getAction()) { > case MotionEvent.ACTION_DOWN: > // Remember our initial down event location. > startx = event.getRawX(); > return true; // first mod, this was still break; > case MotionEvent.ACTION_MOVE: > endx = event.getRawX(); > return true; // first mod, this was still break; > // ADDED: wait for ACTION_UP, and THEN handle the event > case MotionEvent.ACTION_UP: > // Handle (next) > if (endx < startx) > mCurrentPhotoIndex = (mCurrentPhotoIndex + 1) > % mPhotoIds.length; > // Handle (prev) > if (endx > startx) { > mCurrentPhotoIndex = (mCurrentPhotoIndex - 1); > if (mCurrentPhotoIndex < 0) > mCurrentPhotoIndex = mPhotoIds.length - 1; > showPhoto(mCurrentPhotoIndex); > return true; // first mod, this was still break; > } > } > return true; > } > > Note the comments saying that on the first modification, each > of the "return true;" statements in the switch statement were > still left as "break;" ... and later changed to "return true;". > It didn't change the behavior, but for the sake of completeness, > I'm including that bit of info. > > Only one problem. ACTION_UP is apparently never caught. I even > put in a test that bypasses the two if statements (btw, is there > an "else" statement? how would I use it?) and advanced the image > index by 10 ... nothing happened. No change. > > So at this point, while I'm not happy about not being able to > solve this on my own, I am asking for help. > > Later, > --jim > > -- > 73 DE N5IAL (/4) < Running FreeBSD 7.0 > > ICBM / Hurricane: 30.44406N 86.59909W > > "No, try "rm -rf /" > "As your life flashes before your eyes, in > the unit of time known as an ohnosecond...." > (alt.sysadmin.recovery) > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to android-developers@googlegroups.com > To unsubscribe from this group, send email to > android-developers+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en