Android tutorial, lesson 21: gestures

+1 Rip Van Winkle · August 6, 2015
I just installed Android Studio a few days ago, and started working through these excellent tutorials. Everything worked fine until I couldn't get the example code in lesson 21 to recognize any of my gestures. I eventually found a workaround at which fixed the problem for me. Here's the workaround, in case it helps anyone else.

First, add the following import statement:

Then declare the following variable just inside MainActivity:
private MotionEventCompat e;

Then add this code in addition to the gesture detecting procedures from the tutorial:
public boolean onTouchEvent(MotionEvent event){
// Be sure to call the superclass implementation
return super.onTouchEvent(event);

That's it! As a novice, I'm not completely sure why I needed to do this. It looks like something changed between versions? Maybe it's because I'm using AppCompatActivity instead of ActionBarActivity? Or maybe it's something else. This is all very new to me, and I really appreciate that these videos let me jump right in without needing to understand all of the theory first. But if someone could explain a little more about this, I'd be interested.

Post a Reply


Oldest  Newest  Rating
0 Foxpro 007 · August 14, 2015
Hi Rip,

I would be interested as well.

Rip if you are not too tired, sorry bad joke, maybe you could upload all your source code for this module.
I used ActionBarActivity even though it is deprecated but think other people besides me would benefit from seeing all the code from the updated class.

0 Rip Van Winkle · August 18, 2015
Sorry but I only have a very mutated version of that code now, since I continued playing around with the gesture recognition after I got it working. But really, Bucky's original code from the tutorial worked fine after I added the code posted above. In fact, most of the other tutorials seem to still work with AppCompatActivity (which is as it should be). Whenever I find anything that needs to be changed, I've been posting it in an appropriate thread... but most of the tutorial code still seems to work verbatim.
  • 1

Java / Android Development


Very popular language used to create desktop applications, website applets, and Android apps.

Bucky Roberts Administrator