Scala/Android初心者の質問。この単純なコードをJavaからScalaに書き直そうとしています。Java作業コード:
private final SensorEventListener mAccListener = new SensorEventListener() {
public void onSensorChanged(SensorEvent event) {
// ... some code
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
findViewById(R.id.start).setOnClickListener(this);
mSensorManager = (SensorManager)getSystemService(Context.SENSOR_SERVICE);
mAccSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
mSensorManager.registerListener(mAccListener, mAccSensor,
SensorManager.SENSOR_DELAY_GAME);
}
...そしてScala:
package com.example.hello
import android.app.Activity
import android.content.Context
import android.content.Context
import android.hardware.Sensor
import android.hardware.SensorManager
import android.os.Bundle
import android.os.Bundle
import android.view.View.OnClickListener
import android.view.View
import android.view.View
import android.widget.Toast
import android.widget.Toast
import android.hardware.SensorEventListener
class HelloAndroid extends Activity {
def mAccListener (v: View) {
// ... some code
}
override def onCreate(savedInstanceState : Bundle) {
super.onCreate(savedInstanceState)
setContentView(R.layout.main)
findViewById(R.id.start).setOnClickListener(new View.OnClickListener() {
def onClick(v: View) {
Toast.makeText(v.getContext, "Hello World", Toast.LENGTH_LONG).show()
}
})
val mSensorManager = getSystemService(Context.SENSOR_SERVICE).asInstanceOf[SensorManager]
val mAccSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER)
mSensorManager.registerListener(mAccListener(_), mAccSensor,
SensorManager.SENSOR_DELAY_GAME)
}
}
エラーはEclipeの状態です:
Multiple markers at this line
- missing arguments for method mAccListener in class HelloAndroid; follow this method with `_' if you want to treat it as a partially applied function
- overloaded method value registerListener with alternatives: (android.hardware.SensorEventListener,android.hardware.Sensor,Int,android.os.Handler)Boolean <and>
(android.hardware.SensorEventListener,android.hardware.Sensor,Int)Boolean <and> (android.hardware.SensorListener,Int,Int)Boolean <and> (android.hardware.SensorListener,Int)Boolean
cannot be applied to (android.view.View => Unit, android.hardware.Sensor, Int)
私が理解しているように、Scalaはメソッドを呼び出すクラスを見つけることができませんか?どうすれば修正できますか?