Handling UI Events in Android?

You have two onTouchEvent methods in your code. One is in the GestureDetector class (not overridden), and the other is in your Hypertension activity class (which you have overridden at the bottom) When someone triggers the TouchEvent in the main activity you explicitly calling the GestureDetector one (passing down the event) here: if (flingDetector. OnTouchEvent(event)) return true But if you haven't overridden the onTouchEvent method of that class then nothing is going to happen!

The purpose of overriding these "onSomething()" methods is so that they will get called automatically when an event triggers In general the way to work with listeners is as follows: Create a subclass of the Listener class for the event and override its "onEvent()" method to do something when the event is triggered Call the "setListener( Listener)" method of the object you want to trigger said events after it has been initialized--passing in your previously created Listener Sit back and watch :).

You have two onTouchEvent methods in your code. One is in the GestureDetector class (not overridden), and the other is in your Hypertension activity class (which you have overridden at the bottom). When someone triggers the TouchEvent in the main activity you explicitly calling the GestureDetector one (passing down the event) here: if (flingDetector.

OnTouchEvent(event)) return true; But if you haven't overridden the onTouchEvent method of that class then nothing is going to happen! The purpose of overriding these "onSomething()" methods is so that they will get called automatically when an event triggers. In general the way to work with listeners is as follows: Create a subclass of the Listener class for the event and override its "onEvent()" method to do something when the event is triggered Call the "setListener( Listener)" method of the object you want to trigger said events after it has been initialized--passing in your previously created Listener Sit back and watch :).

Thanks so much! I got it working. I simplified my app to respond to clicks instead of gestures and studied how it's syntax fit into your three step process.

Once I understood that, it was just a matter of translating it into a swipe. Is there a way to mark this thread as solved? – dfetter88 Jul 2 '10 at 20:18 Great!

Glad you got it working! And you already marked the thread as solved :) – mxrider Jul 4 '10 at 18:33.

For all event listeners that return a boolean it should return true when it handles the event, so in your example if the flingDetector handles the onTouchEvent it returns true. This question has been posed before and there are some great answers there.

I read throught the page, and noticed I was missing the lines that defined the ontouchlistener for my textviews. I've updated the code above. However, the app is still not working.

I think my main problem is that I don't understand how the methods are working together. What is my final method (onTouchEvent) doing exactly? If the textview is already set up to have a touch handler, it seems to me that this method is useless.

– dfetter88 Jul 2 '10 at 17:55.

On Android, there's more than one way to intercept the events from a user's interaction with your application. The specific View object that the user interacts with. The View class provides the means to do so.

Methods that look useful for UI events. Respective action occurs on that object. The onTouchEvent() method is called on that object.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions