Created
September 6, 2023 09:51
-
-
Save amoozeshbebin/7dcccaa887fa0e2f9d9b40f400b6d657 to your computer and use it in GitHub Desktop.
AlertDialog kotlin android
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.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