Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6093627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:34:55+00:00 2026-05-23T12:34:55+00:00

I have a ViewFlipper which holds a single ImageView. i want to be able

  • 0

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.

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.

Lastly, I added an onSingleTapConfirmed to my GestureDetector. This worked, however it registers a click anywhere in the Activity not just the ImageView.

Can anyone suggest how to narrow down the onSingleTapConfirmed to just work on the Imageview?

Here’s my code so far:

 class MyGestureDetector extends SimpleOnGestureListener {
    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
        try {
            if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
                return false;
            // right to left swipe
            if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > 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() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > 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;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:34:56+00:00Added an answer on May 23, 2026 at 12:34 pm

    I had encountered this problem in the past.

    Maybe you can try to implement single tap by setting an OnTouchListener to ViewFlipper, thus, the ViewFlipper will be the only touch event receiver. Then write the playing sound code in onTouch function. Finally, set onTouch function’s return value to false for the sake of keeping the onFling working.

    viewFlipper.setOnTouchListener(new OnTouchListener()
    {
          @Override
          public boolean onTouch(View view, MotionEvent e) {
              // TODO Auto-generated method stub
              switch(e.getActionMasked())
              {
                 case MotionEvent.ACTION_DOWN:
                      //put the playing sound code here.
                      break;
              }
              return false;  //means that the listener dosen't consume the event
          }
    }
    );
    

    It’s just a simple solution to solve this problem. If you want to achieve more complicated function such as avoiding sound playing when finger is swiping on the screen to change the view, you have to take more effort to distinguish gestures, e.g. calculate the time between ACTION_DOWN event and ACTION_UP event and play the sound if it’s less than 300ms.

    I hope this will be helpful to you. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ViewFlipper with 3 children. I want to be able to display
I have a ViewFlipper that is transitioned between each view, I want to draw
I have a ViewFlipper which contains a few linear layouts. I need to allow
I want to listen to touch events for a viewFlipper. I've been able to
I have a ListView inside of a ViewFlipper which I am flipping when the
I have a ViewFlipper with two ImageView widgets. I have set the in and
In my application I have an activity which contains a viewflipper with 3 listviews
Have just started using Visual Studio Professional's built-in unit testing features, which as I
I have a TabActivity with a tab, which shows a list. I'd like to
Ok I have a ViewFlipper with three LinearLayouts nested inside it. It defaults to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.