将 setText 与有关当前时间的规则结合使用
这是我在 src 中的 .java 文件:
package com.wao.texttime;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class TextTime extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv1 = (TextView) findViewById(R.id.TextView01);
tv1.setText("Good Morning");
TextView tv2 = (TextView) findViewById(R.id.TextView02);
tv1.setText("Good Afternoon");
}
}
我希望 TextView 根据时间显示不同的文本。 F. 前。 08:45-10:45 之间等等。我对 android 和 java 编码都很陌生,我正在尝试弄清楚如何制定显示文本的规则。您有什么建议吗?
This is my .java file in src:
package com.wao.texttime;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class TextTime extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv1 = (TextView) findViewById(R.id.TextView01);
tv1.setText("Good Morning");
TextView tv2 = (TextView) findViewById(R.id.TextView02);
tv1.setText("Good Afternoon");
}
}
I want the TextView to display the different texts depending on what time it is. F.ex. between 08:45-10:45 and so forth. I am very new to coding both for android and in java and I'm trying to figure out how I can make the rules for which text to display. Do you have any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
可能有点复杂。我可能会使用以下方法(进行一些优化)。
It might be a bit more complicated. I would probably use the following approach (withh a bit of optimization ofc.)