var addQuantity = 0 // counter variable
// button_two on clickListener
button_two.setOnClickListener{
val laptopTwo = 500.60
val total_price_two: Double
addQuantity = addQuantity + 1
total_price_two = (addQuantity * laptopTwo).toDouble()
resultDisplayText.text = total_price_two.toString() //displays the result in TextView
}
// button_three on clickListener
button_three.setOnClickListener {
val laptopThree=400.00
val total_price_three:Double
addQuantity = addQuantity + 1
total_price_three =( addQuantity * laptopThree).toDouble()
resultDisplayText.text=total_price_three.toString() //displays the result in TextView
}
//submit button on clickListener
submit.setOnClickListener {
val total: Double
total = total_price_three + total_price_two // get an error here....
}
每次我点击button_two
和button_three
,它都会增加数量并给出数量的总价。现在我想在点击提交按钮时显示总价,但它不起作用。谁能帮我解决这个问题。
该submit
按钮无权访问total_price_two
并且total_price_three
因为它们在本地范围限定为两个按钮的点击侦听器。如果您将它们拉入外部作用域,它们将是可访问的:
var addQuantity = 0 // counter variable
var total_price_two: Double = 0.0
var total_price_three: Double = 0.0
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句