カテゴリー:
睡眠導入
閲覧数:330 配信日:2018-05-06 13:08
コード
▼MainActivity.kt
package work.w4c.android0.introducesleep20180426
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.widget.TextView
import kotlinx.android.synthetic.main.activity_main.*
import java.util.*
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
var greeting = "こんにちは"
val trialTime = Date()
val calendar = GregorianCalendar()
calendar.time = trialTime
val hour = calendar.get(Calendar.HOUR_OF_DAY)
if (hour in 1..11) {
greeting = "おはよう"
} else if (15 < hour) {
greeting = "こんばんは"
}
//greeting += "。。。ひつじが1匹。。。ひつじが2匹。。。ひつじが3匹。。。"
val sheepNum = 10 //追加
for (i in 1..sheepNum) { //追加
greeting += "。。。ひつじが" + i + "匹" //追加
} //追加
textview.text = greeting
//findViewById<TextView>(R.id.textview).text = greeting
}
}