Scala 㧠Android ã¢ããªéçº(Toast ç·¨)
Toast 表示ä¸ã« Toast ã表示ããã¨åé¡ãããããã*1ã®ã§ã次ã®ãããªã©ããã¼ãªãã¸ã§ã¯ããç¨æããã
package ã¯ã準備編ã§ç¨æãããã®ã
package com.github.cooldaemon.HelloWorld import _root_.android.content.Context import _root_.android.widget.Toast object AtomicToast { private[this] var toast: Toast = null def show(message: String)(implicit c: Context) = synchronized { if (toast != null) toast.cancel() toast = Toast.makeText(c, message, Toast.LENGTH_LONG) toast.show() } }
ããã Activity ãã使ãã«ã¯ã次ã®ããã«ããã
package com.github.cooldaemon.HelloWorld // çç¥ class MainActivity extends Activity with TypedActivity { implicit lazy val c: Context = this // çç¥ // ä½ããã®ã¡ã½ããã®ä¸ã§â¦ AtomicToast.show("Selected Foo") // çç¥ }
implicit 㧠Context ã渡ãã®ãå«ãªæ¹ã¯é©å®ä¿®æ£ãã¦ãå©ç¨ãã ããã
*1:å ã«æ¬è¨äºã®ãããªå¯¾çããã¦ãã¾ã£ãã®ã§ãå°ã£ãçµé¨ããªã