Note that there are some explanatory texts on larger screens.

plurals
  1. POOnClick ImageView with OnFling ViewFlipper
    primarykey
    data
    text
    <p>I have a ViewFlipper which holds a single ImageView. i want to be able to swipe to change the image / view, and click the image to play a sound.</p> <p>I have a GestureDetector which is handling OnFling to change the view. I tried to put an onClickListener to the imageview, which worked but stopped the OnFling working.</p> <p>Lastly, I added an onSingleTapConfirmed to my GestureDetector. This worked, however it registers a click anywhere in the Activity not just the ImageView.</p> <p>Can anyone suggest how to narrow down the onSingleTapConfirmed to just work on the Imageview?</p> <p>Here's my code so far:</p> <pre><code> class MyGestureDetector extends SimpleOnGestureListener { @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { try { if (Math.abs(e1.getY() - e2.getY()) &gt; SWIPE_MAX_OFF_PATH) return false; // right to left swipe if(e1.getX() - e2.getX() &gt; SWIPE_MIN_DISTANCE &amp;&amp; Math.abs(velocityX) &gt; SWIPE_THRESHOLD_VELOCITY) { Log.v("Swipe", "Right to Left"); viewFlipper.setInAnimation(slideLeftIn); viewFlipper.setOutAnimation(slideLeftOut); viewFlipper.addView(nextImage(true)); viewFlipper.showNext(); } else if (e2.getX() - e1.getX() &gt; SWIPE_MIN_DISTANCE &amp;&amp; Math.abs(velocityX) &gt; SWIPE_THRESHOLD_VELOCITY) { Log.v("Swipe", "Left to Right"); viewFlipper.setInAnimation(slideRightIn); viewFlipper.setOutAnimation(slideRightOut); viewFlipper.addView(nextImage(false)); viewFlipper.showNext(); } } catch (Exception e) { // nothing } return false; } @Override public boolean onSingleTapConfirmed(MotionEvent e) { // TODO Auto-generated method stub Log.v("SingleTap", "OnSingleTapConfirmed Run"); return super.onSingleTapConfirmed(e); } } private View nextImage(boolean righttoleft) { ImageView imgv1 = new ImageView(this); if(righttoleft == true) { Uri image = Uri.parse("android.resource://com.owentech.brainybaby/drawable/" + variables.letters[variables.currentpos]); imgv1.setImageURI(image); imgv1.setScaleType(ImageView.ScaleType.CENTER_INSIDE); return imgv1; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload