Skip to content

Instantly share code, notes, and snippets.

@codeforfun-jp
Created November 11, 2023 00:22
Show Gist options
  • Save codeforfun-jp/ac0c42332e3f697c6b881921f1289eca to your computer and use it in GitHub Desktop.
Save codeforfun-jp/ac0c42332e3f697c6b881921f1289eca to your computer and use it in GitHub Desktop.
How to create dialog series 1 basic - kotlin 1
package com.example.sample
import android.app.Dialog
import android.os.Bundle
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.DialogFragment
class MyDialogFragment : DialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val dialog = activity?.let {
AlertDialog.Builder(it)
.setTitle("タイトル")
.setMessage("ここにメッセージを入力します")
.setPositiveButton("OK") { dialog, id ->
// ここにコードを書きます
}
.setNegativeButton("キャンセル") { dialog, id -> }
.setNeutralButton("あとで") { dialog, id -> }
.create()
}
return dialog ?: throw IllegalStateException("アクティビティがNullです。")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment