■ はじめに
https://dk521123.hatenablog.com/entry/2013/10/14/002656
https://dk521123.hatenablog.com/entry/2013/10/05/214058
https://dk521123.hatenablog.com/entry/2013/10/06/122942
https://dk521123.hatenablog.com/entry/2013/10/07/005850
https://dk521123.hatenablog.com/entry/2020/07/26/000000
の続き。 今回は、EditText付きダイアログを作成してみる。
■ サンプル
button.setOnClickListener {
val keywordEdit = EditText(this)
val dialog = AlertDialog.Builder(this)
dialog.setTitle("Please input the keyword")
dialog.setView(keywordEdit)
dialog.setPositiveButton("OK", DialogInterface.OnClickListener { _, _ ->
val keyword = keywordEdit.text.toString()
if (keyword.isEmpty()) {
Toast.makeText(
this, "Please input your keyword", Toast.LENGTH_SHORT).show()
return@OnClickListener
}
// 処理
})
dialog.setNegativeButton("Cancel", null)
dialog.show()
}
参考文献
https://thr3a.hatenablog.com/entry/20180326/1521996059
関連記事
ダイアログ表示 ~ 入門編 / トースト・Toast ~
https://dk521123.hatenablog.com/entry/2013/10/14/002656
ダイアログ表示 ~ 基本編 / アラートダイアログ ~
https://dk521123.hatenablog.com/entry/2013/10/05/214058
ダイアログ表示 ~ 基本編 / YES/NO/CANCELボタン ~
https://dk521123.hatenablog.com/entry/2013/10/06/122942
ダイアログ表示 ~ 基本編 / リスト選択 ~
https://dk521123.hatenablog.com/entry/2013/10/07/005850
ダイアログ表示 ~ 基本編 / チェックボックス・ラジオボタン ~
https://dk521123.hatenablog.com/entry/2013/10/09/001500
ダイアログ表示 ~ 基本編 / Notification(通知) ~
https://dk521123.hatenablog.com/entry/2020/08/01/000000