//create a class by extending AlertDialog
class AddItemDialog(
context: Context,
private val listener: OnAddItemListener
) : AlertDialog(context,R.style.AlertDialogStyle) {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
//supportRequestWindowFeature(Window.FEATURE_NO_TITLE)
setContentView(R.layout.layout_add_new)
setTitle("Add New Item")
submit_btn.setOnClickListener(View.OnClickListener {
val title=title.text.toString().trim()
val price=price.text.toString().trim()
if(title.isEmpty() || price.isEmpty()){
Toast.makeText(context, "fill up the form", Toast.LENGTH_SHORT).show()
return@OnClickListener
}
val item =ShoppingItemTable(title,price.toDouble())
listener.onAddItem(item)
dismiss()
})
}
}
interface OnAddItemListener {
fun onAddItem(item: ShoppingItemTable)
}