楼主:
bemaduro (superhotblood)
2018-07-04 15:01:58大家好小弟新手 目前透过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 直接等于零?
谢谢大家!
建议纯新手先从Java开始,至少做个半年以上再考虑用Kotlin,不然什么时候用.text setText之类的问题会让你学习方向失焦
作者:
y3k (激流を制するは静水)
2018-07-05 12:16:00你有写过Java吗...? 这些问题看起来都是连Java都不会在问的@@
楼主:
bemaduro (superhotblood)
2018-07-05 15:25:00谢谢两位前辈回应,那我接下来会去Udemy找个Java的课程
1. countMe用在哪里?感觉像是在xml设定onClick如果是的话那个view代表被按下的View
showCountTextView是一个View(TextView),text是其属性
2. .text 的意思是宣告showCountTextView 是字串吗?
单纯想设成0直接 showCountTextView.text="0" 即可
答案为No,他原本是showCountTextView.setText(xxx)纯新手建议先从Java上手
看起来两个fun都是在xml宣告onclick的 所以view不能少,少了在oncreat的时候就会crash了