Hi, how can I get out of an if condition ? My condition is in a when I precise.
Or maybe can you tell me why afterTextChanged is not working when it’s the first time (maybe because I need text ?)
if(textViewLabel.text == "Quantité"){
input.onFocusChangeListener = View.OnFocusChangeListener { view, hasFocus ->
if (!hasFocus && input.text.toString() != "") {
val quantite = Integer.parseInt(input.text.toString())
input.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {}
override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {}
override fun afterTextChanged(e: Editable?) {
if (e.toString() != "") {
first = false
println("ancienne quantite : $quantite")
val newQuantite = Integer.parseInt(e.toString())
println("nouvelle quantite : $newQuantite")
val valDiff = valDiff(quantite, newQuantite)
println("differ. quantite : $valDiff")
val newPrice = prixDiff(valDiff, 1.0f)
total = totalModif(newPrice, total)
//do this if it's not the first time
textViewLabel.visibility = View.VISIBLE
Toast.makeText(baseContext, total.toString(), Toast.LENGTH_SHORT).show()
} else {
textViewLabel.visibility = View.GONE
}
}
}) // do this the first time
total = calc(quantite, 1.0f, total)
Toast.makeText(baseContext, total.toString(), Toast.LENGTH_SHORT).show()
}
}
}