So i customized a Dialog for data UPDATE which i don’t provide in this question since i think it would be too long. This Dialog would pop if value is found in the database, setting state found = 1.
When the Update Button is clicked, if UPDATE executed correctly then Dialog should be dismissed. The problem is that sometimes it is dismissed incorrectly (dismissed then immediately popped back) or even undismissed. What could possibly be the problem?
Button(
onClick = {
if (newNrp == "" || newNama == ""){
Toast.makeText(context, "Fields may not be blank", Toast.LENGTH_SHORT).show()
}else{
viewModel.viewModelScope.launch{
val status = viewModel.updateMhs(oldNrp, newNrp, newNama)
if (status == -1){
Toast.makeText(context, "Duplicate NRP is not allowed", Toast.LENGTH_SHORT).show()
}else{
Toast.makeText(context, "Updated", Toast.LENGTH_SHORT).show()
found = 0
}
}
}
}
I’ve tried Log.d("FOUND", "$found")
after found = 0
it is 0 but the Dialog popped back anyway. However, removing everything except found = 0
in onClick
scope would dismiss it correctly.
Nizam Hakim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.