I created an activity which has a button, when clicked, shows a dialog box. This dialog box has two buttons, “Confirm” and “Cancel”. When I press cancel, I want to add data to a list and show the list:
class GrillDetailedActivity : AppCompatActivity() {
private val comenziList = mutableListOf<String>()
@SuppressLint("MissingInflatedId")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_grill_detailed)
val imagine: ImageView = findViewById(R.id.detailedImageView)
val nume: TextView = findViewById(R.id.detailedNume)
val cantitate: TextView = findViewById(R.id.detailedCantitate)
val pret: TextView = findViewById(R.id.detailedPret)
val bundle: Bundle? = intent.extras
val imageId = bundle?.getInt("imageId")
val grillName = bundle!!.getString("grillName")
val cantitateGrill = bundle!!.getString("cantitateGrill")
val pretGrill = bundle!!.getString("pretGrill")
imagine.setImageResource(imageId!!)
nume.text = grillName
cantitate.text = cantitateGrill
pret.text = pretGrill
val comandaBtn: Button = findViewById(R.id.buttonComanda)
comandaBtn.setOnClickListener {
val message: String? = "Doriti sa finalizati comanda?"
showCustomDialogBox(message)
}
}
private fun showCustomDialogBox(grillName: String?) {
val dialog = Dialog(this)
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE)
dialog.setCancelable(false)
dialog.setContentView(R.layout.comanda_dialog_box)
dialog.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
val tvMessage: TextView = dialog.findViewById(R.id.tvMessage)
val btnConfirm: Button = dialog.findViewById(R.id.btnConfirm)
val btnAnuleaza: Button = dialog.findViewById(R.id.btnAnuleaza)
val message: String? = "Doriti sa finalizati comanda pentru $grillName?"
tvMessage.text = message
btnConfirm.setOnClickListener {
Toast.makeText(this, "Ati comandat produsul", Toast.LENGTH_SHORT).show()
}
btnAnuleaza.setOnClickListener {
dialog.dismiss()
}
dialog.show()
}
}
New contributor
RaphPaladine is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.