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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:52:58+00:00 2026-05-30T21:52:58+00:00

here is my code now: public boolean onTouchEvent(MotionEvent event) { int action = event.getAction();

  • 0

here is my code now:

public boolean onTouchEvent(MotionEvent event)
        {
            int action = event.getAction();

            switch(action)
            {
                case MotionEvent.ACTION_DOWN:
                // Do click work here ...
                Y -= 10;
                Yopen = 1;
                break;
                case MotionEvent.ACTION_UP:
                // Do release work here ...
                Yopen = 0;
                break;
                }

            return super.onTouchEvent(event);
    } 

But I want to make only three different areas to perform different code.
Can some one help me, some good tutorial on the internet.

  • 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-30T21:53:00+00:00Added an answer on May 30, 2026 at 9:53 pm

    Add this code to your onTouchEvent to figure out where the user touched and respond appropriately:

        //Grab the current touch coordinates
        float x = event.getX();
        float y = event.getY();
    
        //If you only want something to happen then the user touches down...
        if (event.getAction() != MotionEvent.ACTION_UP) return true;
    
        //If the user pressed in the following area, run it's associated method
        if (isXYInRect(x, y, new Rect(x1, y1, x2, y2)))
        {
            //Do whatever you want for your defined area
        }
        //or, if the user pressed in the following area, run it's associated method
        else if (isXYInRect(x, y, new Rect(x1, y1, x2, y2)))
        {
            //Do whatever you want for your defined area
        }
    

    Here’s the isXYinRect method:

    //A helper method to determine if a coordinate is within a rectangle
    private boolean isXYInRect(float x, float y, Rect rect)
    {
        //If it is within the bounds...
        if (x > rect.left &&
            x < rect.right &&
            y > rect.top &&
            y < rect.bottom)
        {
            //Then it's a hit
            return true;
        }
    
        //Otherwise, it's a miss
        return false;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My code is here: public static boolean showConfirmationDialog(Context context, String title, String dialogContent) {
Here is my code for Regex matching which worked for a webpage: public class
I can't post any code right now, since the computer I'm programming on has
Here's a snippet of code: //Game board is made up of Squares. A player
I have the following problem: public Boolean Exists(String userName) { IRepository<User> = new UserRepository();
I'm trying to modify some code I found online to my needs. It is
This post is the continuation of my previous post . Now I have a
So I've been struggling with a problem for a while now, figured I might
I solved the question with onclicklistsner issue with viewpager but now I noticed, that
Originally, I was having some issues getting this code to function, but after a

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.