【发布时间】:2021-09-16 23:00:23
【问题描述】:
我对在 Android Studio 中使用 Kotlin 进行编程非常陌生。 我创建了一个函数,现在我想将函数的结果放入一个文本视图中。 我现在为此苦苦挣扎了几天,但我不知道该怎么做。我使用了我在 Stackoverflow 上找到的基于时间的欢迎消息的函数。就是下面这个函数:
fun getGreetingMessage(): String {
val c = Calendar.getInstance()
val timeOfDay = c.get(Calendar.HOUR_OF_DAY)
return when (timeOfDay) {
in 0..11 -> "Good morning"
in 12..15 -> "Goede afternoon"
in 16..20 -> "Goede evening"
else -> "Hello"
此功能的结果必须在我的主页上的 Textview 中显示,有人可以帮我吗?
非常感谢,
瑞克
【问题讨论】:
-
使用:
myTextVeiw.text = getGreetingMessage()
标签: android function kotlin text textview