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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:20:56+00:00 2026-06-13T03:20:56+00:00

Hello I am creating ViewFlipper like following. <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent android:layout_height=fill_parent android:background=@android:color/white android:orientation=vertical >

  • 0

Hello I am creating ViewFlipper like following.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/white"
android:orientation="vertical" >

<ViewFlipper
    android:id="@+id/vfShow"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
</ViewFlipper>

</LinearLayout>

And handling events like

ViewFlipperSampleActivity.java

public class ViewFlipperSampleActivity extends Activity {

private static final int SWIPE_MIN_DISTANCE = 120;
private static final int SWIPE_THRESHOLD_VELOCITY = 200;

private ViewFlipper vf;
private Context mContext;
private final GestureDetector detector = new GestureDetector(
        new MyGestureDetector());

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.fliper);
    mContext = this;
    vf = (ViewFlipper) this.findViewById(R.id.vfShow);
    vf.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(final View view, final MotionEvent event) {
            detector.onTouchEvent(event);
            return true;
        }
    });

    vf.addView(addImageView(R.drawable.a));
    vf.addView(addImageView(R.drawable.b));
    vf.addView(addImageView(R.drawable.c));
    vf.addView(addImageView(R.drawable.d));

}

View addImageView(int resId) {
    ImageView iv = new ImageView(this);
    iv.setImageResource(resId);

    return iv;
}

class MyGestureDetector extends SimpleOnGestureListener {
    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
            float velocityY) {
        try {

            // right to left swipe
            if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE
                    && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
                vf.setInAnimation(AnimationUtils.loadAnimation(mContext,
                        R.anim.left_in));
                vf.setOutAnimation(AnimationUtils.loadAnimation(mContext,
                        R.anim.left_out));
                vf.showNext();
                return true;
            } else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE
                    && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
                vf.setInAnimation(AnimationUtils.loadAnimation(mContext,
                        R.anim.right_in));
                vf.setOutAnimation(AnimationUtils.loadAnimation(mContext,
                        R.anim.right_out));
                vf.showPrevious();
                return true;
            }

        } catch (Exception e) {
            e.printStackTrace();
        }

        return false;
    }
}

}

Now i am confuse how to play sound at perticular image with viewflipper ? Please help me regarding this.

Thanks

UPDATE :-

public class SoundClass {
static MediaPlayer theme1 = null, theme2 = null, theme3 = null,
        theme4 = null, theme5 = null, theme6 = null;
static MediaPlayer[] mPlayers = { theme1, theme2, theme3, theme4, theme5,
        theme6 };
static Integer[] resources = { R.raw.one, R.raw.two, R.raw.three,
        R.raw.four, R.raw.five, R.raw.six, R.raw.seven, R.raw.eight,
        R.raw.nine, R.raw.ten, R.raw.eleven, R.raw.twelve, R.raw.thirteen,
        R.raw.fourteen, R.raw.fifteen, R.raw.sixteen, R.raw.seventeen,
        R.raw.eighteen, R.raw.ninteen, R.raw.twenty };
static Context ctxt = null;

public SoundClass(Context context) {
    ctxt = context;
}

public static void createAndPlay(int id, Context context) {
    System.out.println(" --- in CreateAndPlay --->>> " + id);
    if (id >= 0 && id <= 20)
        stopAndRelease(id - 1);
    mPlayers[id] = MediaPlayer.create(context, resources[id]);
    if (mPlayers[id] != null && !mPlayers[id].isPlaying()) {
        mPlayers[id].start();
        mPlayers[id].setLooping(false);
    }
}

public static void stopAndRelease(int id) {
    if (id >= 0) {
        // System.out.println(" --- in StopAndRelease if condition --->>> "+id);
        if (mPlayers[id] != null && mPlayers[id].isPlaying()) {
            // System.out.println("in StopAndRelease 2nd if condition --->>> "+" mPlayers[id] -->> "+mPlayers[id]+" mPlayers[id].isPlaying() -> "+mPlayers[id].isPlaying());
            mPlayers[id].stop();
            mPlayers[id].reset();
            mPlayers[id].release();
            mPlayers[id] = null;
        }
    }
}

public static void mute(int id) {
    if (mPlayers[id] != null && mPlayers[id].isPlaying()) {
        mPlayers[id].pause();
    }
}

public static void unMute(int id) {
    if (mPlayers[id] != null && !mPlayers[id].isPlaying()) {
        mPlayers[id].start();
    }
}

}

    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
            float velocityY) {
        try {

            // right to left swipe
            if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE
                    && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
                vf_letters.setInAnimation(AnimationUtils.loadAnimation(
                        mContext, R.anim.left_in));
                vf_letters.setOutAnimation(AnimationUtils.loadAnimation(
                        mContext, R.anim.left_out));

                if (count < 20) {
                    count += 1;
                    // if (isMute)
                    SoundClass.createAndPlay(count, LettersScreen.this);
                    vf_letters.showNext();
                } else {
                    SoundClass.stopAndRelease(count);
                    count = 0;
                    // if(isMute)
                    SoundClass.createAndPlay(count, LettersScreen.this);
                }
                return true;
            } else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE
                    && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
                vf_letters.setInAnimation(AnimationUtils.loadAnimation(
                        mContext, R.anim.right_in));
                vf_letters.setOutAnimation(AnimationUtils.loadAnimation(
                        mContext, R.anim.right_out));

                if (count > 0) {
                    SoundClass.stopAndRelease(count);

                    count -= 1;
                    // if (isMute)
                    SoundClass.createAndPlay(count, LettersScreen.this);
                    vf_letters.showPrevious();
                } else {
                    SoundClass.stopAndRelease(count);
                    count = 20;
                    // if(isMute)
                    SoundClass.createAndPlay(count, LettersScreen.this);
                    vf_letters.showPrevious();

                }

                return true;
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;

    }
  • 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-06-13T03:20:57+00:00Added an answer on June 13, 2026 at 3:20 am

    This may not be perfect but gives idea about how to implement

    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) 
                {                   
                    analogflipper.setInAnimation(slideLeftIn);
                    analogflipper.setOutAnimation(slideLeftOut);                    
    
    //                  System.out.println(" Flipping next... ");
                        if(count < 5)
                        {
                            count += 1;  
                            if(isMute)
                                SoundClass.CreateAndPlay(count, AnalogClockTime.this);      
                            analogflipper.showNext();
                        }
                        else
                        {
                            SoundClass.StopAndRelease(count);
                            count = 0;
                            if(isMute)
                                SoundClass.CreateAndPlay(count, AnalogClockTime.this);      
                            analogflipper.showNext();
                        }
                        /*else
                            count = 0;*/
    
                    }  
                    else if(e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) 
                    {                       
                        analogflipper.setInAnimation(slideRightIn);
                        analogflipper.setOutAnimation(slideRightOut);                   
    
    //                  System.out.println(" Flipping previous... ");
                        if(count > 0)
                        {
                            SoundClass.StopAndRelease(count);
    
    
                        count -= 1;
                        if(isMute)
                            SoundClass.CreateAndPlay(count, AnalogClockTime.this);
                        analogflipper.showPrevious();
                    }
                    else
                    {
                        SoundClass.StopAndRelease(count);  
                        count = 5;
                        if(isMute)
                            SoundClass.CreateAndPlay(count, AnalogClockTime.this);
                        analogflipper.showPrevious();
                    }
                    /*else
                        count = 4;*/
    
    
                    }
                } 
                catch (Exception e) 
                {
    //                System.out.println("Exception...");
                }
                return false;
            }
        }
    

    This class handles all sound creation, playing etc tasks

    public class SoundClass 
    {   
    
    static MediaPlayer theme1 = null, theme2 = null, theme3 = null, theme4 = null, theme5 = null, theme6 = null;
        static MediaPlayer[] mPlayers = { theme1, theme2, theme3, theme4, theme5, theme6 };
        static Integer[] resources = {R.raw.theme1, R.raw.theme2, R.raw.theme3, R.raw.theme4, R.raw.theme5, R.raw.theme6};
        static Context ctxt = null;
    
    public SoundClass(Context context) 
    {
        ctxt = context;
    }
    
    public static void createAndPlay(int id, Context context)
    {
    System.out.println(" --- in CreateAndPlay --->>> "+id);
            if(id >= 0 && id <= 5)
                StopAndRelease(id - 1);
            mPlayers[id] = MediaPlayer.create(context, resources[id]);
            if(mPlayers[id] != null && !mPlayers[id].isPlaying())
            {
                mPlayers[id].start();
                mPlayers[id].setLooping(true);
            }
        }
    
    public static void stopAndRelease(int id)
    {
        if(id >= 0)
        {
    //          System.out.println(" --- in StopAndRelease if condition --->>> "+id);
                if(mPlayers[id] != null && mPlayers[id].isPlaying())
                {
    //              System.out.println("in StopAndRelease 2nd if condition --->>> "+" mPlayers[id] -->> "+mPlayers[id]+" mPlayers[id].isPlaying() -> "+mPlayers[id].isPlaying());
                    mPlayers[id].stop();
                    mPlayers[id].reset();
                    mPlayers[id].release();
                    mPlayers[id] = null;
                }
            }       
        }
    
    public static void mute(int id)
    {
        if(mPlayers[id] != null && mPlayers[id].isPlaying())
        {
            mPlayers[id].pause();
        }
    }
    
    public static void unMute(int id)
    {
        if(mPlayers[id] != null && !mPlayers[id].isPlaying())
        {
            mPlayers[id].start();
        }
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using this tutorial: http://www.c-sharpcorner.com/uploadfile/UrmimalaPal/creating-a-windows-phone-7-application-consuming-data-using-a-wcf-service/ I have created sample/hello world application on the windows phone
Hello I am trying to create an animation like creating heart like bubbles but
I'm creating a bitmap font label like so: CCLabelBMFont *label = [CCLabelBMFont labelWithString:@Hello fntFile:@HeaderFont.fnt
Hello everyone, I need help on creating a button like in the above picture.
Hello I'm creating application for android no mater what kind but I need to
I am practicing from the book Hello,Android ed3.There is an example code on creating
I am currently creating a small HTTP server that returns a static page <p>Hello!</p>
Hello I'm creating a game and I have a few ways to make trainers
Hello I am creating a Windows application (WPF) that is going to be running
Hello I am creating a CMS and some of the functionality of it that

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.