I want to fill the ProductList
in the code below but it's always null.
do you have any solution?
fun nameValidation(name: TextInputEditText, cactusDao: CactusDao): String? {
val nameText = name.text.toString()
var productList = listOf<String>()
GlobalScope.launch(Dispatchers.IO) {
productList = cactusDao.getAllProductNames()
}
if (productList.contains(nameText)) {
return "Product already Exists!"
}
if (nameText.isNullOrEmpty() || nameText.isNullOrBlank()) {
return "Field is Empty!"
}
return null
}
i expected it fills the ProductList
, but nothing happened. ProductList
is still null and the condition doesn't work
UPDATE(doe to request of darjow):
i used that nameValidation
here:
productName.setOnFocusChangeListener { _, focused ->
if (!focused) {
productNameContainer.helperText =
ProductValidator.nameValidation(productName, cactusDao)
}
}
which is inside of AlertDialog
class that handles alertDialogs.
and im using this AlertDialog
class in a floatingActionButton.setOnClickListener{}