I am attempting to convert the following tutorial, http://savagelook.com/blog/android/swipes-or-flings-for-navigation-in-android, into Scala code for an开发者_如何学Godroid. I have everything working well, except for MyGestureDetector class which I have not yet completed but already have errors in. My code is as follow
class MyGestureDetector extends SimpleOnGestureListener {
override def onFling(e1:MotionEvent, e2:MotionEvent, velocityX:Float, velocityY:Float):Boolean ={
var intent:Intent = new Intent (MainActivity.this.getBaseContext(), MainActivity.class)
true
}
override def onDown(e:MotionEvent):Boolean = {
true
}
}
My code is giving me a red underline on the MainActivity.this.getBaseContext() and the MainActivity.class. The red x next to the line says that MainActivity is not an enclosing class, that an identifier was expected but .class found, and that MainActivity is not a value. I am importing the following packages
import android.app.Activity
import android.os.Bundle
import android.content.Intent
import android.view.GestureDetector
import android.view.GestureDetector.SimpleOnGestureListener
import android.view.MotionEvent
import android.view.View
Can anyone point out where I am going wrong?? Thank you all
Michael
Try this.:
val myIntent = new Intent(CurrentActivity.this, classOf[DestinationActivity])
The first parameter should be the instance of the current activity. ( Since Activity extends Context, and the current Context is needed)
精彩评论