Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8275935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:13:40+00:00 2026-06-08T08:13:40+00:00

Scala/Android newbie question. I’m trying to rewrite this simple code from Java to Scala.

  • 0

Scala/Android newbie question.
I’m trying to rewrite this simple code from Java to Scala.
Java working code:

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);
}

…and 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)

  }
}

The error is Eclipe states:

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)

As I understand Scala can’t find out which class to call method from? How can I fix it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T08:13:42+00:00Added an answer on June 8, 2026 at 8:13 am

    “mAccListener(_)” creates a function of type android.view.View => Unit. But there’s no version of registerListener that takes such a function.

    The Java version is passing in a SensorListener. Shouldn’t the Scala version do the same?

    You’re probably thinking of an implicit conversion from View => Unit to SensorListener… if so, you need to build it yourself.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Newbie Java question - On all the posts for Auto Scaling the Text view,
I've been trying to experiment with developing Android applications with Scala. I've gotten to
I'm starting with Scala + Android (and using the sbt android plugin). I'm trying
I am a newbie and I have been working on an android layout for
I'm having problems running the scala-android plugin when running sbt from inside IntelliJ. When
I am following the video on this page http://zegoggl.es/2009/12/building-android-apps-in-scala-with-sbt.html which use SBT to create
This is an Android question: I am taking a jpeg picture taken with the
I'm trying to play with Scala in Android but the Manifest doesn't recognizes my
I'm trying to rotate and then scale an image using android.graphics.Matrix. The code is
I currently working on my personal project in Android. I'm quite a newbie in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.