Develop Android Application in Eclipse with Scala Language

1. Download and install Eclipse Classic 3.7.2

Note: I will not go into details about downloading JDK and Android SDK. If you have any questions, you can ask me

2. Install Android ADT Plugin

Installation address: https://dl-ssl.google.com/android/eclipse/

3. Install Scala IDE

Installation address: http://download.scala-ide.org/releases-29/milestone/site/

4. Install AndroidProguardScala

Installation address: https://androidproguardscala.s3.amazonaws.com/UpdateSiteForAndroidProguardScala

5. Create Android Project

6、Add Scala Nature

Right-click on the android project, Configure->Add Scala Nature

7、Add AndroidProguardScala Nature

Right-click on the android project, Add AndroidProguardScala Nature

8. Adjust the Java Build Path order (important)

Note that the two scala libs are moved to the top of Android
Develop Android Application in Eclipse with Scala Language

9. Replace Java's Activity class with scala's Activity class

package org.noahx.scalaandroid

import android.app.Activity
import android.os.Bundle
import android.widget.Button
import android.widget.TextView
import android.view.View

class ScalaAndroidActivity extends Activity {
  
 override protected def onCreate(savedInstanceState: Bundle) = {
    super.onCreate (savedInstanceState)

    setContentView(R.layout.main)

    val text = findViewById(R.id.text1).asInstanceOf[TextView]
    val button = findViewById(R.id.button1).asInstanceOf[Button]
    
    button.setOnClickListener(new View.OnClickListener() {

      def onClick(v: View) = {
        text.setText("hello scala!!!")
      }

    })
  }
 
}
Note: After modifying the layout, clean the project

10. Operation effect

Develop Android Application in Eclipse with Scala Language 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326364901&siteId=291194637