大家好小弟新手 目前透過Udemy自學 Android
目前在做一個 Counter 的小程式 程式碼如下
有幾個疑問想要提問
fun countMe (view: View) {
括號內的(view: View) 的意義是??
不宣告的話app 又會crash
// Get the text view.
val showCountTextView = number
// Get the value of the text view.
val countString = showCountTextView.text.toString()
//Convert value to a number and increment it
var count: Int = Integer.parseInt(countString)
count++
// Display the new value in the text view.
showCountTextView.text = count.toString()
.text 的意思是宣告showCountTextView 是字串嗎?
}
fun reSet (view: View) {
// Get the text view.
val showCountTextView = number
//Convert value to 0
val zeroing = 0
// Display the new value in the text view.
showCountTextView.text = zeroing.toString()
}
這個功能的目的是要讓數字歸零,已修改讓他更簡潔。有更直接的做法嗎?
例如讓number 這個TextView 直接等於零?
謝謝大家!