var price = productPrice.text.toString().toInt()
- вы пытаетесь конвертировать "16000 $" в Int здесь. Пожалуйста, сначала получите подстроку.
Формально правильный код:
val priceText = productPrice.text.toString()
val price = priceText.substring(0, priceText.length - 1).toInt()
Однако на самом деле я советую вам хранить значение внутри. Ваша цена является частью модели. Например, вы можете избежать разбора текста и просто прочитать значение из модели. Например, код будет выглядеть так:
var price = intent.getIntExtra("price") // we store int value here, not String
var inc_val= price
decrease.isEnabled=false
displayPrice()
increase.setOnClickListener {
intent.setIntExtra(intent.getIntExtra("price") + inc_val) // read, update, save
displayPrice()
}
decrease.setOnClickListener {
intent.setIntExtra(intent.getIntExtra("price") - inc_val) // read, update, save
displayPrice()
}
/*this function just shows price*/
fun displayPrice() {
val price = intent.getIntExtra("price")
productprice.text= "$price\$"
}