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 6342885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:19:43+00:00 2026-05-24T20:19:43+00:00

I am working on an Android project in which I use a ViewFlipper for

  • 0

I am working on an Android project in which I use a ViewFlipper for flipping childs. For this I used a customized flipper. In this I override the onTouchEvent() method.
The flipper contain images in each child but when I try to flip it doesn’t receive any touch event. When I override the ViewGroup method onInterceptTouchEvent() and return true, then flipping is done but due to this my onClickEvent() on each image is not received.

I am not getting where the problem is. When I return false from onInterceptTouchEvent() then the click event is being received but not the touch event.

What am I missing?

Code for the ViewFlipper:

public class MyViewFlipper extends ViewFlipper {

    static final String logTag = "ViewFlipper";
    static final int MIN_DISTANCE = 30;
    private float downX, downY, upX, upY;
    Animation slideLeftIn;
    Animation slideLeftOut;
    Animation slideRightIn;
    Animation slideRightOut;
    Context context;
    ViewFlipper viewFlipper;

    public MyViewFlipper(Context context) {
        super(context);
        viewFlipper=this;
        this.context=context;
        System.out.println("I am in MyFlipper() counstructor...");
    }

    public MyViewFlipper(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context=context;
        viewFlipper=this;
        System.out.println("I am in MyFlipper() counstructor...");
        slideLeftIn =
            AnimationUtils.loadAnimation(context, R.anim.slide_left_in);
        slideLeftOut =
            AnimationUtils.loadAnimation(context, R.anim.slide_left_out);
        slideRightIn =
            AnimationUtils.loadAnimation(context, R.anim.slide_right_in);
        slideRightOut =
            AnimationUtils.loadAnimation(context, R.anim.slide_right_out);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN: {
                downX = event.getX();
                downY = event.getY();
                return true;
            }
            case MotionEvent.ACTION_UP: {
                upX = event.getX();
                upY = event.getY();

                float deltaX = downX - upX;
                float deltaY = downY - upY;

                // swipe horizontal?
                if (Math.abs(deltaX) > MIN_DISTANCE) {
                    // left or right
                    if (deltaX < 0) {
                        this.onLeftToRightSwipe();
                        return true;
                    }
                    if (deltaX > 0) {
                        this.onRightToLeftSwipe();
                        return true;
                    }
                } else {
                    if(Math.abs(deltaX)<15){
                        onClickEvent();
                    }
                    //Log.i(logTag, "Swipe was only " + Math.abs(deltaX)
                    //+ " long, need at least " + MIN_DISTANCE);
                }
                // swipe vertical?
                if (Math.abs(deltaY) > MIN_DISTANCE) {
                    // top or down
                    if (deltaY < 0) {
                        this.onTopToBottomSwipe();
                        return true;
                    }
                    if (deltaY > 0) {
                        this.onBottomToTopSwipe();
                        return true;
                    }
                } else {
                    Log.i(logTag, "Swipe was only " + Math.abs(deltaX)
                        + " long, need at least " + MIN_DISTANCE);
                }

                return true;
            }
        }
        return false;

    }

    public void onRightToLeftSwipe() {

        viewFlipper.setInAnimation(slideLeftIn);
        viewFlipper.setOutAnimation(slideLeftOut);
        viewFlipper.showNext();
    }

    public void onLeftToRightSwipe() {

        viewFlipper.setInAnimation(slideRightIn);
        viewFlipper.setOutAnimation(slideRightOut); 
        viewFlipper.showPrevious();
    }

    public void onTopToBottomSwipe() {
        Log.i(logTag, "onTopToBottomSwipe!");
        // activity.doSomething();
    }

    public void onBottomToTopSwipe() {
        Log.i(logTag, "onBottomToTopSwipe!");
        // activity.doSomething();
    }

    public void onClickEvent(){
        Toast.makeText(context, "Click",Toast.LENGTH_SHORT);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        return true;    // Here if true then Flipping done.
                        // And if false then click event done. 
    }

}
  • 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-24T20:19:45+00:00Added an answer on May 24, 2026 at 8:19 pm

    I had a similar problem.
    Here is what i did. I had a listview in my view flipper and i override the setOnTouchListener() of my listview and animated the view flipper from there. It worked for me.

    Try overriding the setOnTouchListener() of ImageView in your case.

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

Sidebar

Related Questions

I am working on a project which includes an Android application which is used
I'm working on an Android app in which I would like to use multi-touch.
I am new to android platform. I am working on a project in which
I am working on a project which requires the use of Google Maps and
My team is working on an Android project which consists of several Android applications
I am new to android. I am working on a project which uses map.
I am working on an android sms gateway project which receives sms from client
When I try to run my Android project(which was working fine yesterday) I get
I am working on an android project which requires me to build the android's
I am working with the sample Home application project on http://developer.android.com/resources/samples/Home/index.html I've added another

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.