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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:01:08+00:00 2026-05-21T22:01:08+00:00

My application contains an area filled with buttons. I wish to implement the activity

  • 0

My application contains an area filled with buttons. I wish to implement the activity in such way, that fling gesture over the button area would switch it to one of two another areas (using ViewFlipper).

I’ve made two approaches on detecting gestures. The first one involved using GestureDetector. However, the touch motion events over the Button didn’t raised the onTouchEvent activity method, so – in result – I couldn’t have forwarded it to the GestureDetector class. A failure, in short.

The second approach – involved using the GestureOverlayView. This time, however, I’ve reached the second extreme: not only the gesture was detected, but also the button, over which gesture is performed, reported a click.

I wish the interface to work in the following way: if user touches button and releases the touch (or moves the finger only a little), the button reports click and no gesture is detected. On the other hand, if user touches the screen and makes a longer move, the gesture shall be detected and no click event reported by the button.

I’ve implemented a small proof-of-concept application. The activity XML code follows:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent"  xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical">
  <android.gesture.GestureOverlayView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/overlay">
    <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical">
    <TextView android:id="@+id/display" android:layout_width="match_parent" android:layout_height="wrap_content" />
    <Button android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/button"/>
    </LinearLayout>
  </android.gesture.GestureOverlayView>
</LinearLayout>

The activity java code follows:

package spk.sketchbook;

import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import android.gesture.*;
import android.gesture.GestureOverlayView.OnGestureListener;

public class Main extends Activity implements OnGestureListener, OnClickListener
{       
  private void SetupEvents()
  {
    GestureOverlayView ov = (GestureOverlayView)findViewById(R.id.overlay);
    ov.addOnGestureListener(this);

    Button b = (Button)findViewById(R.id.button);
    b.setOnClickListener(this);
  }

  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState)
  {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    SetupEvents();
  }

  @Override
  public void onGesture(GestureOverlayView arg0, MotionEvent arg1)
  {
    TextView tv = (TextView)findViewById(R.id.display);
    tv.setText("Gesture");
  }

  @Override
  public void onGestureCancelled(GestureOverlayView arg0, MotionEvent arg1)
  {

  }

  @Override
  public void onGestureEnded(GestureOverlayView overlay, MotionEvent event)
  {

  }

  @Override
  public void onGestureStarted(GestureOverlayView overlay, MotionEvent event)
  {

  }

  @Override
  public void onClick(View v)
  {
    TextView tv = (TextView)findViewById(R.id.display);
    tv.setText("Click");
  }


}

The question is: how to implement such an interface, which can decide, if user action shall be treated as the gesture or button click?

Best regards — Spook.

  • 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-21T22:01:09+00:00Added an answer on May 21, 2026 at 10:01 pm

    Solved myself. The idea is to catch gesture events from GestureOverlayView and, apart from passing them to GestureDetector, measure the distance of user’s gesture. The distance shall be stored in a private activity’s field (thus available for all event handlers). Finally, fling and click handlers shall check the value of this field; if it is below certain value (say, 10 pixels shall be fine), it should be interpreted as a click. Otherwise – as a gesture.

    Note, that the button will both look clicked and its click handler will be called. I’ve decided to create a low-level click handler (attached to all buttons over GestureOverlayView), which does the gesture/click check and if the result is a click, chooses one of higher-level click handlers.

    The solution works for me; however if one wished to disable the clicked look of button and prevent the handler from being called, it would probably involve redefining the button and/or GestureOverlayView components.

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

Sidebar

Related Questions

My application contains a piece of code that executes inside of Component Services, so
My Facebook application contains Javascript that works in Firefox and IE, but aborts in
We have a windows application that contains an ActiveX WebBrowser control. As part of
I have a console application that contains quite a lot of threads. There are
We currently have a quite complex business application that contains a huge lot of
I am working on an ASP.NET MVC application that contains a header and menu
I have a web application (.war) that contains some static files (e.g. MS word
I have an asp.net mvc 2.0 application that contains Areas/Modules like calendar, admin, etc...
My application has a table that contains snapshot inventory data from each year. For
I have a win forms application that contains a Web Browser control. I need

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.