Questions tagged [android-event]

On Android, there's more than one way to intercept the events from a user's interaction with your application. When considering events within your user interface, the approach is to capture the events from the specific View object that the user interacts with. The View class provides the means to do so. Questions that regard doubt about any type of events action (listeners and handlers), should use this tag to express themselves.

Within the various View classes that you'll use to compose your layout, you may notice several public callback methods that look useful for UI events. These methods are called by the Android framework when the respective action occurs on that object. For instance, when a View (such as a Button) is touched, the onTouchEvent() method is called on that object. However, in order to intercept this, you must extend the class and override the method. However, extending every View object in order to handle such an event would not be practical. This is why the View class also contains a collection of nested interfaces with callbacks that you can much more easily define. These interfaces, called event listeners, are your ticket to capturing the user interaction with your UI.

While you will more commonly use the event listeners to listen for user interaction, there may come a time when you do want to extend a View class, in order to build a custom component. Perhaps you want to extend the Button class to make something more fancy. In this case, you'll be able to define the default event behaviors for your class using the class event handlers.

For a more detailed information you can visit Google oficial webpage about Events at Google Developer - Events

318 questions
84
votes
11 answers

How to distinguish between move and click in onTouchEvent()?

In my application, I need to handle both move and click events. A click is a sequence of one ACTION_DOWN action, several ACTION_MOVE actions and one ACTION_UP action. In theory, if you get an ACTION_DOWN event and then an ACTION_UP event - it means…
some.birdie
  • 2,259
  • 4
  • 24
  • 28
32
votes
2 answers

View.onTouchEvent only registers ACTION_DOWN event

I'm implementing a custom TextView and I want to do some action when the view is touched. I figured the onTouchEvent method would give me the full range of touches on the view without having to use setOnTouchListener (I'm trying to do all my work…
Jason Robinson
  • 31,005
  • 19
  • 77
  • 131
27
votes
9 answers

Android get value of the selected radio button

I have a RadioGroup rg1 and I want to get the value of the selected radio button. I know that I can get the id of the selected radio button by using: if(rg1.getCheckedRadioButtonId()!=-1) int id= rg1.getCheckedRadioButtonId() that gives me the id…
Totti
  • 665
  • 5
  • 12
  • 26
20
votes
2 answers

onTouchEvent executes twice

Can anyone explain to me why is the onTouchEvent executed twice and how can I set it to run only once? I couldn't find an explanation. Thanks. @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); …
slybloty
  • 6,346
  • 6
  • 49
  • 70
15
votes
2 answers

Detecting android softkeyboard show/hide events

I am trying to detect showKeyboard and hidekeyboard events on phonegap. For that purpose, on deviceready event I placed following code: bindEvents: function() { document.addEventListener('deviceready', this.onDeviceReady, false); }, //…
Hafiz
  • 4,187
  • 12
  • 58
  • 111
12
votes
1 answer

Android - Listener for catching changes in a View's properties (e.g. android:layout_marginTop)

In Android, can you create a Listener for catching changes in a View's properties (width / height / margin / position relative to top of the screen)? I want to trigger an event when layout_marginTop="10dp" is changed to a different value.
Jack
  • 430
  • 2
  • 5
  • 19
12
votes
9 answers

How can I send key events in android?

I am macking a custom navigation bar to Android 4.0.3.r1 and want to send key events like "Home" and "Back". My application is not a system therefore: IWindowManager mWindowManager = IWindowManager.Stub.asInterface( …
Sergei Vasilenko
  • 2,313
  • 2
  • 27
  • 38
11
votes
2 answers

GestureDetector.SimpleOnGestureListener. How do I detect an ACTION_UP event?

Using this mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() { @Override public boolean onSingleTapUp(MotionEvent e) { return true; } Only detects for single tap event…
Ersen Osman
  • 7,067
  • 8
  • 47
  • 80
11
votes
7 answers

Receiving onTouch and onClick events with Android

I have a view that need to process onTouch gestures and onClick events. What is the proper way to achieve this? I have an onTouchListener and an onClickListener set on the view. Whenever I do touch the view, first the onTouch event is triggered and…
theV0ID
  • 4,172
  • 9
  • 35
  • 56
9
votes
1 answer

Want to Access Power Button events in android

i=0; public boolean onKeyDown(int keyCode, KeyEvent event) { System.out.println("In Key Down Method." + event.getKeyCode()); if (event.getKeyCode() == KeyEvent.KEYCODE_POWER) { i++; System.out.println("Power button…
Anil Ravsaheb Ghodake
  • 1,587
  • 2
  • 27
  • 45
8
votes
1 answer

Show Dialog using PendingIntent

I am working on Calender Events reminder . There is no native Calender events reminder in Android so user install different calender apps. Now these apps can be different on reminding events like on reminder notifications can be shown. Now I want…
User42590
  • 2,473
  • 12
  • 44
  • 85
7
votes
3 answers

Optimal method for posponing onEvent?

In my little app, I receive a series of queued onEventXXX(), from the system (not controlled by me). The timing of those onEventXXX() is not guaranteed. The only thing guaranteed is that they are received in the order in which they were put into the…
Bill The Ape
  • 3,261
  • 25
  • 44
7
votes
1 answer

Differentiate Regular Menu KeyEvent from IME Opening

In listening for key events in ActionBarSherlock in order to show the overflow menu on pre-ICS devices and am I'm facing an interesting problem. It would seem that I am unable to differentiate a simple key press versus when the user is long-pressing…
Jake Wharton
  • 75,598
  • 23
  • 223
  • 230
7
votes
1 answer

Why does view.startAnimation(animation) not work when called from an event?

I have created a custom view which uses an dummy TranslateAnimation to setup some layout properties. I use the Interpolator to calculate height, and apply it to a view inside the applyTransformation() method of the TranslateAnimation. This is…
david.schreiber
  • 3,851
  • 2
  • 28
  • 46
7
votes
1 answer

Dispatch touch event from a view to his WebView sibling

Resume of the problem : dispatch touch event on a layout to his WebView sibling achieving the same scroll than the default WebView scroll (with fling) I have a frameLayout over an WebView following this xml :
Hugo Gresse
  • 17,195
  • 9
  • 77
  • 119
1
2 3
21 22