Skip to content

Instantly share code, notes, and snippets.

@amoozeshbebin
Created September 6, 2023 09:51
Show Gist options
  • Save amoozeshbebin/7dcccaa887fa0e2f9d9b40f400b6d657 to your computer and use it in GitHub Desktop.
Save amoozeshbebin/7dcccaa887fa0e2f9d9b40f400b6d657 to your computer and use it in GitHub Desktop.
AlertDialog kotlin android
package com.example.alerdialog
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import androidx.appcompat.app.AlertDialog
class MainActivity : AppCompatActivity() {
lateinit var bottom:Button
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
init()
}
fun init(){
bindView()
bottom.setOnClickListener {
var builder = AlertDialog.Builder(this)
builder.setPositiveButton(R.string.yes){_,_ -> finish()}
builder.setNegativeButton(R.string.no){_,_ -> }
builder.setIcon(android.R.drawable.ic_dialog_alert)
builder.setTitle("Quit App")
builder.setMessage("are you sure to quit app?")
var alertDialog:AlertDialog = builder.create()
alertDialog.show()
builder.show()
}
}
fun bindView(){
bottom = findViewById(R.id.btndialog)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment