-1

how to How to Replace text with a predetermined time example: at 12:00 text turns into afternoon, at 3:00 text changed to good evening? explanation please :)

my custom text :

public texttime(Context ct)
{
    super(ct);
}
public texttime(Context ct,AttributeSet attrs)
{
    super(ct,attrs);
    //start
    if(Time.is....(12:00)
    {
        setText("good afternoon");
    }
}

thanks :)

1 Answers1

1

You can get Current hour from instance of Calender class like below

int nowHour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);

Then you can use a if-else ladder like below

if(nowHour>=0 &&<nowHour<=6)
{
  textView.setText("late night");
}
else if(nowHour>=7 &&<nowHour<=11)
{
   textView.setText("morning");
}
else if(nowHour>=12 &&<nowHour<=15)
{
   textView.setText("noon");
}
else if(nowHour>=16 &&<nowHour<=18)
{
   textView.setText("afternoon");
} //and so on
Zahan Safallwa
  • 3,880
  • 2
  • 25
  • 32