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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:45:21+00:00 2026-06-09T01:45:21+00:00

How can I display a toast message from within a class which extends ImageView.

  • 0

How can I display a toast message from within a class which extends ImageView. I’d like to place it in the onDoubleTap method so it displays a message to the user as to what pixel was just double tapped. I have the following two classes:

public class TouchImageView extends ImageView 
{
  ....
   final GestureDetector mGestureDetector = new GestureDetector(new GestureDetector.SimpleOnGestureListener() 
    {
        @Override
        public boolean onDoubleTap(MotionEvent e) 
        {           
            Toast.makeText(getApplicationContext(), "Pixel",  Toast.LENGTH_SHORT).show();

            return true;
        }
        ...
   }

public class DisplayMap extends Activity 
{
  int width;
  int height;
  double imageSize;

  @Override
  public void onCreate(Bundle savedInstanceState) 
  {
    super.onCreate(savedInstanceState);

    TouchImageView img = new TouchImageView(getApplicationContext());

    Bitmap mapImage = BitmapFactory.decodeResource(getResources(), R.drawable.testimage);
    img.setImageBitmap(mapImage);
    img.setMaxZoom(4f);
    setContentView(img);
    ...
}

The code above won’t work because
getApplicationContext() is undefined for ImageView.

Thanks

  • 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-09T01:45:23+00:00Added an answer on June 9, 2026 at 1:45 am

    Have your TouchImageView class a constructor that accepts a Context object.

    Context context;
    
    public TouchImageView(Context context) {
        super(context); //Thanks for this tip
        this.context = context;      
    }
    
    final GestureDetector mGestureDetector = new GestureDetector(new GestureDetector.SimpleOnGestureListener() 
    {
        @Override
        public boolean onDoubleTap(MotionEvent e) 
        {           
            Toast.makeText(context, "Pixel",  Toast.LENGTH_SHORT).show();
    
            return true;
        }
        ...
    }
    

    And send your Activity.this object in the TouchImageView object

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

Sidebar

Related Questions

I can display a simple Visual Basic inputbox from a PowerShell script like this:
How can I display Toast messages from a thread?
How I can display a message for a few seconds without using Toast on
I wonder if someone can help me. I'm trying to display a toast element
How i can display all applications icons and name which are installed in device
Is there any firefox addon which can display my asp.net page viewstate size.... Any
I want to develop JSF page which can display the swap size if the
I have an application which requires data to be fetched from a received message
I want to display toast message inside timer and I used the following code
I am using Toast.makeText to display results from dialogs and having a slightly odd

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.