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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:24:25+00:00 2026-06-09T07:24:25+00:00

Newbie question. I am using an ImageView in my activity layout and would like

  • 0

Newbie question.
I am using an ImageView in my activity layout and would like similar behavior to a button. I notice that ImageView already generates onClick. What it doesn’t do is provide any visual feedback at touch and un-touch, which is what I’d like to add.

As well, I am going to need long-press handling; don’t yet know if ImageView does that.

I’ve dug in a bit and it I see that View implements Runnable; something is calling performClick when the user taps on the image, which then calls ImageView.PerformClick, which finally calls onClick for all the listeners (which is my activity). By the time ImageView handles PerformClick, it’s too late to change the image appearance; how do I do it at onShowPress time?

One more note: I’ve looked at (and tried) adding a gestureDetector to ImageView, but then it appears that I need to reimplement the onClick processing – at any rate, the activity stopped receiving onClick.

There may be a completely different way to do what I want and I’m open to hear about it.

Thanks.

Edit:
Test code for monitoring touch actions:
package com.example.mockup;

import android.content.Context;
import android.util.AttributeSet;
import android.view.DragEvent;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageButton;

public class ImageGestureButton extends ImageButton
   implements View.OnTouchListener, View.OnClickListener, View.OnDragListener,
   View.OnLongClickListener
{
  public ImageGestureButton (Context context, AttributeSet attrs)
  {
    super(context, attrs);
    setOnTouchListener (this);
    setOnClickListener (this);
    setOnLongClickListener (this);
    setOnDragListener (this);
    setLongClickable (true);
  }

  public boolean onTouch (View v, MotionEvent e)
  {
    System.out.println ("onTouch " + e.getAction());
    return false;
  }

  public void onClick (View v)
  {
    System.out.println ("onClick");
  }

  public boolean onDrag (View v, DragEvent e)
  {
    System.out.println ("onDrag");
    return false;
  }

  public boolean onLongClick (View v)
  {
    System.out.println ("onLongClick");
    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-09T07:24:26+00:00Added an answer on June 9, 2026 at 7:24 am

    I would use an ImageButton. Then use setOnClickListener() to wire up the method you want to be called when you click on it. In addition, you can use setOnLongClickListener() for the long press behavior.

    Finally, you can also set different backgrounds, colors, etc. depending on the state (focused, selected, etc.). Take a look at the documentation.

    As for the test code, your onLongClick() is returning false, which indicates that the long click wasn’t consumed. Try changing the return value to true and that should stop onClick() from also getting fired. Also, you’ll need to call the startDrag() method in order to fire the onDrag() event. See the android.view documentation for more info on the different event listeners and the startDrag() method.

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

Sidebar

Related Questions

another newbie-question regarding rails and bootstrap. I am using something like this: <div class=tabbable
Newbie question. I have Django models that look like this: class Video(models.Model): uploaded_by =
Another newbie question. I would like to be able to import a .CSV spreadsheet
Newbie question since I'm not up to speed using maven at all. I'm trying
Absolute newbie question, any help is highly appreciated :) I am using curvycorners (
Newbie question: I just installed VisualSVN Server and created a repository. I noticed that
Newbie question here: I'm using ANSI C on server to crunch numbers for a
Newbie question. I'm trying to make a mobile site using html5's geolocation (I know
Newbie question... I am using silverlight to POST data to my GAE application class
This is a newbie question. Is the migration (rake db:migrate) feature something that one

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.