I am making an app in kotlin language. I want to change that Good morning textview to good evening when time is between 4 pm to 8pm and goodnight when time is in range of night time and agin to good morning when time pasts 12 am.
how can i do it in kotlin?
2
Simply get hour like this:
val currentHour = Calendar.getInstance().get(Calendar.HOUR)
And set text, based on the hour.
text.text = if(currentHour > 20 && currentHour < 4) "Good evening" else "Good morning"
//Set greeting
val greetingtext = findViewById<TextView>(R.id.greeting) val currentHour = Calendar.getInstance().get(Calendar.HOUR) greetingtext.text = if(currentHour < 13 && currentHour < 4) "Good afternoon!" else "Good morning!" greetingtext.text = if(currentHour < 18 && currentHour < 18 ) "Good evening!" else "Good evening!"
Click here to cancel reply.
2
Answers
Simply get hour like this:
And set text, based on the hour.
//Set greeting