Kotlin 我不熟悉科特林语。有人能帮我添加显示在不同onClickListener上的两个总值吗?
每次我点击按钮二和按钮三,它都会增加数量并给出数量的总价。现在我想在点击提交按钮时显示总价格,但它不起作用。有人能帮我解决这个问题吗。提交按钮无法访问Kotlin 我不熟悉科特林语。有人能帮我添加显示在不同onClickListener上的两个总值吗?,kotlin,Kotlin,每次我点击按钮二和按钮三,它都会增加数量并给出数量的总价。现在我想在点击提交按钮时显示总价格,但它不起作用。有人能帮我解决这个问题吗。提交按钮无法访问总价二和总价三,因为这两个按钮的点击监听器都在本地。如果将它们拉入外部范围,则可以访问它们: var addQuantity = 0 // counter variable // button_two on clickListener button_two.setOnClickListener{
总价二
和总价三
,因为这两个按钮的点击监听器都在本地。如果将它们拉入外部范围,则可以访问它们:
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....
}
请多花点时间,将问题中的代码格式化为所述格式。原来如此,它很难阅读。谢谢你的帮助,虽然我已经解决了它。
var addQuantity = 0 // counter variable
var total_price_two: Double = 0.0
var total_price_three: Double = 0.0