检查空 TextView 的时间、日期和 setText(类似于日程表,如果星期天时间在 16:00 和 17:00 之间,setText 为 "Naptime")

Check the time , day and setText of an empty TextView (Like a Schedule, if time is between 16:00 and 17:00 on a sunday setText to "Naptime")

ANDROID 我的资源-: 按钮按钮 文本视图 textview_empty

我想制作一个功能来检查时间和-: setText textview_empty 到一个特定的文本。 请帮忙 如果是 javascript,代码将是:

<p id=a></p>
<script>

var currentTime = new Date().getHours();
if (currentTime >= 16 && currentTime <= 17) {
   document.body.style.background = "#58FA58";
} else {
    document.body.style.background = "#013ADF";
}

您可以使用

TextView mTextView;
mTextView = (TextView) findViewById(R.id.textview_empty);

Calendar calendar = Calendar.getInstance();
String hour = String.valueOf(calendar.get(Calendar.HOUR));
String minute = String.valueOf(calendar.get(Calendar.MINUTE));
String seconds = String.valueOf(calendar.get(Calendar.SECOND));

String formattedTime = hour + ":" + minute + ":" + seconds;

mTextView.setText(formattedTime);