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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:28:37+00:00 2026-05-29T11:28:37+00:00

Imagine a layout with 4 buttons _______________________________ | | | | A | B

  • 0

Imagine a layout with 4 buttons

 _______________________________
|              |                |
|      A       |       B        |
|______________|________________|
|              |                |
|      C       |       D        |
|______________|________________|

I’d like to detect the fling gesture over the whole layout but when the fling starts over a button is no detected.

I’m using:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    gesturedetector= new GestureDetector(this, this);

    findViewById(R.id.touchContainer).setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            Log.e("","TouchEvent");
            return gesturedetector.onTouchEvent(event);
        }
    });
}

It when there is no clickable items but fails if the fling start over a clickable item.

How can I solve that? Offering a bounty of 50 point for a complete working answer

  • 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-29T11:28:38+00:00Added an answer on May 29, 2026 at 11:28 am

    One way I have achieved this is to override the following method:

    public boolean onInterceptTouchEvent(MotionEvent event){
        super.onInterceptTouchEvent(event);
        ...
    

    You can override this method in your layout container (e.g. ViewGroup, or whatever you’re holding the buttons with) and continue to return false from it in order to ‘intercept’ touch events that are being consumed by child Views (i.e. your buttons). Within that overridden method you can then call your gesture detector object with the MotionEvents. This method also ‘sees’ events that target the ViewGroup itself as well, which means – if I remember correctly – you would only need to call your gesture detector from within that method, and in doing so the gesture detector will ‘see’ all events, no matter whether they’er over the buttons or not. So if you drag your finger starting over a button and then ending at some point on the layout background, the gesture detector should see the entire swipe. You would not need to feed the gesture detector with the events from the layout’s own onTouchEvent() because it’ll have already seen them.

    A second way:

    I just looked at my project where I used this, and realised that I switched to a different way of doing it. What I actually did was I designed all of my child Views such that the parent Activity (or the containing ViewGroup) could register the same gesture detector object with all of those child Views (each of my special Views have a method called registerGestureDetector()). Then, in the overridden ‘onTouchEvent()’ in my child Views, I pass the MotionEvents to the gesture detector that has been registered with that View. In other words, the parent ViewGroup layout and all the child Views simply share the same gesture detector.

    I realise that this may sound like a bit of hassle and not necessary considering it could be done using onInterceptTouchEvent(), but my application deals with some pretty complicated rules regarding how my Views need to respond to touch events and gestures, and it allowed me to apply some additional logic that I needed specific for my application. However, both of these methods I’ve used achieve the same basic objective here: to channel the MotionEvents that targetted various Views to the same gesture detector object.

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

Sidebar

Related Questions

I would like to achieve this specific type of radio buttons in my layout:
I've got a page layout for a publishing site with an odd behaviour. Imagine
Whats the best way to get this layout in CSS? imagine that I have
Imagine we have a program trying to write to a particular file, but failing.
I read http://android-developers.blogspot.com/2012/01/say-goodbye-to-menu-button.html but have some issues. For pre-honeycomb I want a custom title,
Imagine the following (simplified) database layout: We have many holiday records that relate to
Let's imagine situation where you're making the layout for a webpage. In HTML you
imagine this layout of classes i use for building a tree structure: class Treenodebase
Imagine an application that has a number of buttons it is displaying to the
I'm writing an image viewer, and I'd like some behavior from Qt: imagine the

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.