samedi 31 octobre 2020

kotlin - Problem with my if statement and operator

This is my goal : user click on minus button the amount decrease by one and there is a if statement to not allow the amount go lower than 0 .

This is my Code :

   var number = 0
        view.text_amount.visibility = View.GONE

        view.plus_btn.setOnClickListener {

            if (number == 5) {
                Toast.makeText(
                    requireContext(),
                    "Limit in order",
                    Toast.LENGTH_SHORT
                ).show()
            } else {
                view.text_amount.visibility = View.VISIBLE
                number++
                view.text_amount.text = number.toString()
            }
        }
        view.minus_btn.setOnClickListener {
            if (number <= 0) {
                view.text_amount.visibility = View.GONE
            } else {
                number--
                view.text_amount.text = number.toString()

            }

        }

there is problem with code : I don't want the amount be visible after getting to 0 . it's better experience when the amount is equal to 0 not be visible .

I think it has a simple solution but I can't see it . do you have any idea ?

Aucun commentaire:

Enregistrer un commentaire