トップ 一覧 ping 検索 ヘルプ RSS ログイン

Kotlin Androidの変更点

  • 追加された行はこのように表示されます。
  • 削除された行はこのように表示されます。
!!!Kotlin Android
[Kotlin][Android]
!!通知
!通知サンプル
*http://typea.info/blg/glob/2018/11/android-kotlin.html

!!画面遷移
!Intent
 val intent = Intent(this, SecondActivity::class.java)
 startActivity(intent)

!Navigationのヘッダー上のオブジェクトにアクセス
 (nav_view.getHeaderView(0)?.findViewById<TextView>(R.id.user_email) as TextView)?.text = currentUser.email.toString()
 
!!Web
![Web API JSON 呼び出し|http://typea.info/blg/glob/2018/07/android-kotlin-retrofit2-web-api-json.html]
!!!Kotlin Android Extensions
*https://kotlinlang.org/docs/tutorials/android-plugin.html

!!準備
::build.gradle
 apply plugin: 'kotlin-android-extensions'
::import
 import kotlinx.android.synthetic.main.<layout>.*

!!イベントリスナー例
*以下のように簡素に書ける
 import kotlinx.android.synthetic.main.activity_function_check.*
 
 class FunctionCheckActivity : AppCompatActivity() {
 
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
         setContentView(R.layout.activity_function_check)
 
         btn_notification.setOnClickListener {
             Toast.makeText(this,"test",Toast.LENGTH_SHORT).show()
         }
     }
 }