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

  • Home
  • SEARCH
  • 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 8091369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:02:49+00:00 2026-06-05T20:02:49+00:00

I try to make an imageview clickable. Actually it is clickable, so that I

  • 0

I try to make an imageview clickable.
Actually it is clickable, so that I can call an Intent after the user touches the imageview.
But I am struggeling to change the image on touch.

I want the following:

  • Default (no touch) : Image1
  • User touches the imageview: change to image2
  • User moves with finger out of imageview : change back to Image1
    (without calling Intent)
  • User untouches imageview: call Intent and switch back to Image1

Some of these things are working with the following code:

final ImageView v = (ImageView) findViewById(R.id.profileImage);

    v.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View arg0, MotionEvent arg1) {
            switch (arg1.getAction()) {
            case MotionEvent.ACTION_DOWN: {
                   v.setImageResource(R.drawable.ic_contact_picture_down);

                break;
            }


            case MotionEvent.ACTION_CANCEL:{

                v.setImageResource(R.drawable.ic_contact_picture);
                break;

            }

            case MotionEvent.ACTION_UP: {

                takePhoto();

                v.setImageResource(R.drawable.ic_contact_picture);
                break;
            }

            }
            return true;
        }
    });

The image changes on touch correctly to image2. So the ACTION_DOWN is working.
ACTION_UP is called if the user untouches the imageview. But it is also called if the untouch is done outside of the imageview. If this occurs I want to switch to image1 back but not call takePhoto() function.
ACTION_CANCEL is never called, which I considered to be the candidate for the above case.

  • 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-05T20:02:50+00:00Added an answer on June 5, 2026 at 8:02 pm

    You can try use a Rect to hold the bounds of the ImageView and then use ACTION_MOVE

    For example, declare a Rect object,

    private Rect rect;
    

    Then in your setOnTouchListener(), initialize the Rect and check using ACTION_MOVE,

    v.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View arg0, MotionEvent arg1) {
            switch (arg1.getAction()) {
              case MotionEvent.ACTION_DOWN: {
                // Declare the bounds of the rect
                rect = new Rect(v.getLeft(), v.getTop(), v.getRight(), v.getBottom());   
                v.setImageResource(R.drawable.ic_contact_picture_down);
    
                break;
              }
    
              case MotionEvent.ACTION_MOVE:{
                if(!rect.contains((int)arg1.getX(), (int)arg1.getY())) {
                    // Outside the bounds
                    v.setImageResource(R.drawable.ic_contact_picture);
                }
                break;        
              }
    
              case MotionEvent.ACTION_UP: {
    
                takePhoto();
    
                v.setImageResource(R.drawable.ic_contact_picture);
                break;
              }
            }
            return true;
        }
    });
    

    Sorry I haven’t tested this but I think you can get the idea 🙂

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

Sidebar

Related Questions

I try to make a apps that need barcode scanner, i already can get
I can make a gesture which detects a movement when the user touches the
I try to make a registration form. When user post the fields, i check
I try to make an animation with an image in my view but it
I am working on ProgressBar class in android, but I can't make it progress
I want to try and put this into a loop, but I can't seem
hwy buddy i try to make my album view for that i put my
Databinding in WPF is great, but the moment you try make things more complex
I try to make the background of my window transparent. But under widgets which
I try to make fade in/out effect for UIView border but it does'nt work.

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.