Dialog Builder in Kotlin
Set your default dialog in MainActivity
demo:
After clicking any button you can show dialoug
in
button.setOnClickListener{
val dialogBuilder=AlertDialog.Builder(this@MainActivity)
dialogBuilder.setTitle("Hey Stop")
dialogBuilder.setMessage("Do yo0u want to go to the next page?")
dialogBuilder.setPositiveButton("Yes",
DialogInterface.OnClickListener{
dialogInterface: DialogInterface?, which: Int ->
val intent=Intent(this,ListActivity::class.java)
startActivity(intent)
})
dialogBuilder.setNegativeButton("No",DialogInterface.OnClickListener{
dialog: DialogInterface?, which: Int ->
Toast.makeText(this@MainActivity,"Sorry",Toast.LENGTH_LONG).show()
})
val alertDialog=dialogBuilder.create()
alertDialog.show()
}
Set your Custom Alert Dialog in MainActivity
button.setOnClickListener{
val view=layoutInflater.inflate(R.layout.alert_dialog,null)
val dialogBuilder=AlertDialog.Builder(this@MainActivity)
dialogBuilder.setView(view)
dialogBuilder.setTitle("Hey Stop")
dialogBuilder.setMessage("Do yo0u want to go to the next page?")
val alertDialog=dialogBuilder.create()
alertDialog.show()
val editTextrr=view.findViewById<EditText>(R.id.editTextrr)
view.buttonShoww.setOnClickListener {
val namee=editTextrr.text.toString()
Toast.makeText(this@MainActivity,"$namee",Toast.LENGTH_LONG).show()
alertDialog.dismiss()
}
view.buttonCancel.setOnClickListener {
Toast.makeText(applicationContext,
"I Can not Show Your name",Toast.LENGTH_LONG).show()
alertDialog.dismiss()
}
}
}