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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:38:09+00:00 2026-05-27T03:38:09+00:00

I have an activity which has an ImageView in it. What I want to

  • 0

I have an activity which has an ImageView in it. What I want to do is be able to draw where the user touches that Imageview with an image from the drawable folder. I’ve read that the best way is to use Canvas, but I’m not sure where and how I integrate the onDraw method with the onTouchListener. This is what I have so far:

public class Main extends Activity
{
   @Override
   public void onCreate(Bundle savedInstanceState)
   {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);

      final TextView textView = (TextView)findViewById(R.id.textView);
      final ImageView image = (ImageView) findViewById(R.id.imageView2);

      //Bitmap
      Bitmap viewBitmap = Bitmap.createBitmap(image.getWidth(), image.getHeight(), Bitmap.Config.ARGB_8888);
      Canvas canvas = new Canvas(viewBitmap);
      image.draw(canvas);

      image.setOnTouchListener(new View.OnTouchListener()
      {
         @Override
         public boolean onTouch(View v, MotionEvent event)
         {
            textView.setText("Touch coordinates : " + String.valueOf(event.getX()) + "x" + String.valueOf(event.getY()));
            return false;
         }
      });
   }
}

So what I want to do is when the user touches the ImageView, an image will be drawn exactly where he touched it.

  • 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-27T03:38:10+00:00Added an answer on May 27, 2026 at 3:38 am

    You’re going to want to subclass ImageView in order to override its onDraw() method. By doing so, you can also to the custom touch handling in onTouchEvent() instead of attaching a listener. This is not a complete example, but something like the following:

    public class CustomImageView extends ImageView {
    
        private ArrayList<Point) mTouches;
        private Bitmap mMarker;
    
        //Java constructor
        public CustomImageView(Context context) {
            super(context);
            init();
        }
    
        //XML constructor
        public CustomImageView(Context context, AttributeSet attrs) {
            super(context, attrs);
            init();
        }
    
        private void init() {
            mTouches = new ArrayList<Point>();
            mMarker = BitmapFactory.decodeResource(context.getResources(), R.drawable.my_marker_image);
        }
    
        @Override
        public boolean onTouchEvent(MotionEvent event) {
            //Capture a reference to each touch for drawing
            if(event.getAction() == MotionEvent.ACTION_DOWN) {
                mTouches.add( new Point(event.getX(), event.getY()) );
                return true;
            }
    
            return super.onTouchEvent(event);
        }
    
        @Override
        protected void onDraw(Canvas c) {
            //Let the image be drawn first
            super.onDraw(c);
    
            //Draw your custom points here
            Paint paint = new Paint();            
            for(Point p : mTouches) {
                c.drawBitmap(mMarker, p.x, p.y, paint);
            }
        }
    
    }
    

    HTH!

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

Sidebar

Related Questions

I have a ImageView which shows a picture that has been taken from the
I have an Activity class which has an attribute that references an AsyncTask instance
I have a custom activity which has inargument<MyClass>. MyClass has several properties. I want
I have an Activity A which has a "down" button (see image above). When
I have an Activity that has a main.xml with an ImageView. I then launch
I have a activity which has a button and 2 autocomplete widget. for the
Guys I have an activity which has a home button, when the button is
I have an activity which consists of a ListView . The problem is that
I have an Activity which uses a Fragment . I simply want to pass
I have an extended BaseAdapter that has LinearLayout children (an ImageView and a TextView

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.