If you do not like the Alert Dialog builder method here is a easy custom Alert Dialog
This btnDeleteDept calls the doCustom() fun
btnDeleteDept.setOnClickListener {
if (etDeptData.text.toString().equals("")) {
message("No Match Found")
return@setOnClickListener
}
doCustom()
}
Here is the code for the doCustom() fun it uses another fun as you can see
fun doCustom() {
/* This method uses the custom_dialog.xml file created for greater control over
the styling of the Custom Alert Dialog for various screen sizes and to be
able to set the text size of the dialog message text
*/
val makeDialog = LayoutInflater.from(this).inflate(R.layout.custom_dialog,null)
val mBuilder = AlertDialog.Builder(this).setView(makeDialog)
val mAlertDialog = mBuilder.show()
val btnYES = makeDialog.findViewById<Button>(R.id.btnYES)
val btnNO = makeDialog.findViewById<Button>(R.id.btnNO)
mAlertDialog.setCancelable(false)
btnYES.setOnClickListener {
removeDEPT()
mAlertDialog.dismiss()
}
btnNO.setOnClickListener {
message("Record NOT Deleted")
etDeptData.setText("")
//Timer().schedule(800){
thisACTIVITY()
//}
mAlertDialog.dismiss()
}
mAlertDialog.show()
}
private fun removeDEPT() {
val dbHandler = DBHelper(this)
val result = dbHandler.deleteDEPT(etDeptData.text.toString())
if (result) {
etDeptData.setText("")
message("Record Removed")
//Timer().schedule(1000){
thisACTIVITY()
//}
}else{
etDeptData.setText("NO MATCH -> click View Dept List")
btnViewDeptList.visibility = View.VISIBLE
btnEditDept.visibility = View.INVISIBLE
btnDeleteDept.visibility =View.INVISIBLE
btnSaveDeptData.visibility = View.INVISIBLE
message("NO Match Found")
}
}
OK all this is nothing without the XML file
<?xml version="1.0" encoding="utf-8"?>
<ImageView
android:id="@+id/imgDI"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:src="@drawable/delete48" />
<TextView
android:id="@+id/tvDAT"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="80dp"
android:layout_marginTop="30dp"
android:text="Delete Data"
android:textColor="@color/color_Black"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="@+id/tvDAC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="28dp"
android:layout_marginTop="80dp"
android:gravity="center"
android:text="Click DELETE to Remove Data"
android:textColor="@color/color_Black"
android:textSize="18sp"
android:textStyle="bold" />
<Button
android:id="@+id/btnYES"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="240dp"
android:layout_marginTop="110dp"
android:background="@color/color_Transparent"
android:text="DELETE"
android:textColor="@color/color_deepBlue"
android:textSize="18sp"
android:textStyle="bold" />
<Button
android:id="@+id/btnNO"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="110dp"
android:background="@color/color_Transparent"
android:text="CANCEL"
android:textColor="@color/color_deepBlue"
android:textSize="18sp"
android:textStyle="bold" />