Last active
January 7, 2019 07:38
-
-
Save shingohry/4442899accbfb8728306f78c73d4f30e to your computer and use it in GitHub Desktop.
MainActivity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.myfirstapp | |
import android.content.Intent | |
import android.support.v7.app.AppCompatActivity | |
import android.os.Bundle | |
import android.widget.Button | |
import android.widget.EditText | |
class MainActivity : AppCompatActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
// ----- 以下を追加する ----- | |
// Buttonへの参照を取得する | |
val button = findViewById<Button>(R.id.button) | |
// ボタンタップ時の処理を指定する | |
button.setOnClickListener { | |
// EditTextへの参照を取得する | |
val editText = findViewById<EditText>(R.id.editText) | |
// メッセージを取り出す | |
val message = editText.text.toString() | |
// Intentを作成する | |
val intent = Intent(this, ResultActivity::class.java) | |
// パラメータをセットする | |
intent.putExtra("message", message) | |
// 画面を遷移させる | |
startActivity(intent) | |
} | |
// ------------------------ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment