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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:07:22+00:00 2026-05-26T13:07:22+00:00

I need some help. In my android app I have a ViewFlipper that contains

  • 0

I need some help. In my android app I have a ViewFlipper that contains some LinearLayout. On every LinearLayout I have a ImageView. For switching between screens I use this code :

LinearLayout layMain = (LinearLayout) findViewById(R.id.layout_main);
        layMain.setOnTouchListener((OnTouchListener) this);

//————–

public boolean onTouch(View arg0, MotionEvent arg1) {

        // Get the action that was done on this touch event
        switch (arg1.getAction()) {
        case MotionEvent.ACTION_DOWN: {
            // store the X value when the user's finger was pressed down
            downXValue = arg1.getX();
            break;
        }

        case MotionEvent.ACTION_UP: {
            // Get the X value when the user released his/her finger
            float currentX = arg1.getX();

            // going backwards: pushing stuff to the right
            if (downXValue < currentX) {
                // Get a reference to the ViewFlipper
                ViewFlipper vf = (ViewFlipper) findViewById(R.id.details);
                // Set the animation
                vf.setOutAnimation(AnimationUtils.loadAnimation(this,
                        R.anim.push_right_out));
                vf.setInAnimation(AnimationUtils.loadAnimation(this,
                        R.anim.push_right_in));

                // Flip!
                vf.showPrevious();
            }

            // going forwards: pushing stuff to the left
            if (downXValue > currentX) {
                // Get a reference to the ViewFlipper
                ViewFlipper vf = (ViewFlipper) findViewById(R.id.details);
                // Set the animation
                // vf.setInAnimation(AnimationUtils.loadAnimation(this,
                // R.anim.push_left_in));
                vf.setOutAnimation(AnimationUtils.loadAnimation(this,
                        R.anim.push_left_out));
                vf.setInAnimation(AnimationUtils.loadAnimation(this,
                        R.anim.push_left_in));
                // Flip!
                vf.showNext();
            }
            break;
        }
        }

        // if you return false, these actions will not be recorded
        return true;
    }

Every screen contains a ImageView.So, when I switch the screens the imageview is changing. Now I want to implement this: When an image is clicked a url to be open. Here is my code :

ViewFlipper vf = (ViewFlipper) findViewById(R.id.details);

        for (i = 0; i < jArray.length(); i++) {
            LinearLayout l = new LinearLayout(this);
            l.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
                    LayoutParams.FILL_PARENT));
            l.setBackgroundColor(0x000000);
            l.setOrientation(LinearLayout.VERTICAL);
            vf.addView(l);

            ImageView img = new ImageView(this);
            img.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
                    LayoutParams.FILL_PARENT));
            Drawable image1 = ImageOperations(getBaseContext(), url[i]);
            img.setImageDrawable(image1);
            System.out.println("target" + target[i]);
            img.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri
                            .parse("http://google.com"));
                    startActivity(browserIntent);
                }
            });

            l.addView(img);
        }

The problem is that everytime I touch the screen the url is open and now I can’t switch between screens. How to do this, to make the differents between onClick() and on Touch()?

Please help me..
Thanks in advance

  • 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-26T13:07:22+00:00Added an answer on May 26, 2026 at 1:07 pm

    I think you use image View like a background for Linear Layout , it seems Activity handle the touch for ImageView , to achieve your Functionality setTouch listener for imageView and we can handle the click for image view indirectly using following code in OntouchListener,

    if (downXValue == currentX) {
    Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri
                            .parse("http://google.com"));
                    startActivity(browserIntent);}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating an Android app utilising OpenGL ES, and need some help with the
I am trying to create my first Android app and need some help. Basically
I need some help with threading in my app. Ive got an activity that
I need some help dealing with three Threads in Android One thread is the
Need some help about with Memcache. I have created a class and want to
Need some help, please. I have a line of horizontal thumbnails loaded as ONE
Need some help to solve this. I have a gridview and inside the gridview
Need some help from javascript gurus. I have one page where http://www.google.com/finance/converter is embedded
Need some help assigning a mouseover event to display some icons that start out
I need some help from the shell-script gurus out there. I have a .txt

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.