Here is a code that may solve your purpose.The concept is simple.Just take the time you want to validate from Calendar class and compare it with the current time and then take an appropiate action.
TextView textView = (TextView) findViewById(R.id.text);
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(System.currentTimeMillis());
cal.set(Calendar.HOUR_OF_DAY, 3);
cal.set(Calendar.MINUTE, 00);
cal.set(Calendar.SECOND, 0);
long noon_start = cal.getTimeInMillis();//3.00
cal.set(Calendar.HOUR_OF_DAY, 5);
cal.set(Calendar.MINUTE, 30);
long noon_end = cal.getTimeInMillis();//5.30
long now = System.currentTimeMillis();//current time
if(now > noon_start && now < noon_end)
{
textView.setText("Good afternoon");
}
else
{
textView.setText("Good Evening");
}
1
solved android: textView.setText when time 03.00 until 05.30 [closed]