Where is onTouchEvent called?

Started by
3 comments, last by alh420 7 years, 2 months ago

I could not find this method called "public Boolean onTouchEvent(MotionEvent event) anywhere in my code. I was wondering where it could be called with no luck. Is this method called automatically? Are all the built in methods than need to be overridden called automatically?

Advertisement

You need to provide more framing for your question. I see that you are tagged the post with Android, but are you writing this in straight Java or another game engine?

If you're writing in Java than you have to call and define the onTouchEvent.

Developer with a bit of Kickstarter and business experience.

YouTube Channel: Hostile Viking Studio
Twitter: @Precursors_Dawn

I'm writing in java sorry about that.

I did define "public Boolean onTouchEvent(MotionEvent event)" in an override method but I cannot find where this method is called and executed. I expected to see it in my Mainthread class within my overridden run() method but it was not there. Now I have a method that I don't understand when and where it is

I know this method is built in and a description says it is called everytime I tap my phones screen but that is not important to me.

I know this method is built in and a description says it is called everytime I tap my phones screen but that is not important to me.


Yes it comes from within built in classes and function so you probably wont be able to see exactly how/where it is called. It is called automatically by the system when a touch event occurs. You don't need to do anything more than override that function to receive and respond to the event.

The android developer documentation is pretty handy. See https://developer.android.com/training/gestures/detector.html and https://developer.android.com/reference/android/view/View.html for onTouchEvent descriptions

If you put a breakpoint in your onTouchEvent, you should be able to see in your debugger where it is called from, if you are really curious.

You could also download the source code to android, and see exactly how it works.

But it is not vital information, as noted above, you can just rely on it being called by the OS/application framework when needed.

This topic is closed to new replies.

Advertisement