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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:02:20+00:00 2026-06-14T17:02:20+00:00

How do I detect the touch event if the user touches on view A

  • 0

How do I detect the touch event if the user touches on view A and drags to bottom over the view B. I want to detect the touch event in View B.

I added touch listener in view B but doesn’t receive events if the user initially touched A and dragged over the B.

enter image description here

  • 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-14T17:02:23+00:00Added an answer on June 14, 2026 at 5:02 pm

    You can use the code bellow to achive your request:

    Method to test view bounds (used in code beloow)

        Rect outRect = new Rect();
        int[] location = new int[2];
    
        private boolean isViewInBounds(View view, int x, int y){
            view.getDrawingRect(outRect);
            view.getLocationOnScreen(location);
            outRect.offset(location[0], location[1]);
            return outRect.contains(x, y);
        }
    

    Testing with two TextView

        final TextView viewA = (TextView)  findViewById(R.id.textView);
        final TextView viewB = (TextView)  findViewById(R.id.textView2);
    

    Setup viewA

    The empty OnClickListener is required to keep OnTouchListener active until ACTION_UP

        viewA.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {}
        });
    
        viewA.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                int x = (int)event.getRawX();
                int y = (int)event.getRawY();
                if(event.getAction() == MotionEvent.ACTION_UP){
                    if(isViewInBounds(viewB, x, y))
                        viewB.dispatchTouchEvent(event);
                    else if(isViewInBounds(viewA, x, y)){
                        Log.d(TAG, "onTouch ViewA");
                        //Here goes code to execute on onTouch ViewA
                    }
                }
                // Further touch is not handled
                return false;
            }
        });
    

    Setup viewB

    This is only required if you also want to press on viewB and drag to viewA

        viewB.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {}
        });
    
        viewB.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                int x = (int)event.getRawX();
                int y = (int)event.getRawY();
                if(event.getAction() == MotionEvent.ACTION_UP){
                    if(isViewInBounds(viewA, x, y))
                        viewA.dispatchTouchEvent(event);
                    else if(isViewInBounds(viewB, x, y)){
                        Log.d(TAG, "onTouch ViewB");
                        //Here goes code to execute on onTouch ViewB
                    }
                }
                // Further touch is not handled
                return false;
            }
        });
    

    Regards.

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

Sidebar

Related Questions

I have a UILabel control in a view. I want to detect touch event
I want to detect the touch edge in onTouchEvent function for my view, but
I have used 4 images and use touches began method to detect user's touch
My objective is to detect any touch event inside My Application on any view...
I'm trying to detect when a user touches down and up in a view.
I have a draggable view that a user will touch, but some rectangles of
I know how to detect a double-click and a two-finger touch event, but how
I want to detect when a user taps anywhere in a view in my
I want to use Modernizr to detect whether a user is view a site
I am new to iPhone Developer, I want to detect touch in my webview

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.