如何在Android中的TextView更改文本 [英] how to change text in Android TextView
问题描述
我试图做到这一点
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
t=new TextView(this);
t=(TextView)findViewById(R.id.TextView01);
t.setText("Step One: blast egg");
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
t.setText("Step Two: fry egg");
但由于某些原因,只有第二个文本显示,当我运行它。我想可能有一些做与视频下载()
办法阻止。因此,有人可以告诉我如何实现一个计时器异步?
but for some reason, only the second text shows up when I run it. I think it might have something to do with the Thread.sleep()
method blocking. So can someone show me how to implement a timer "asynchronously"?
感谢。
推荐答案
我刚刚发布了Android,谷歌讨论组的这个答案
I just posted this answer in the android-discuss google group
如果您只是想添加文本视图,以便显示步骤一:爆蛋第二步:炒鸡蛋那可以考虑使用 t.appendText(第二步:煎鸡蛋 );
而不是 t.setText(第二步:炒鸡蛋);
If you are just trying to add text to the view so that it displays "Step One: blast egg Step Two: fry egg" Then consider using t.appendText("Step Two: fry egg");
instead of t.setText("Step Two: fry egg");
如果你想彻底改变什么是在的TextView
,以便它说:第一步:爆蛋的启动,然后它说:第二步:煎鸡蛋在时间后,你可以随时使用
If you want to completely change what is in the TextView
so that it says "Step One: blast egg" on startup and then it says "Step Two: fry egg" at a time later you can always use a
Runnable的例子sadboy了
Runnable example sadboy gave
好运气
这篇关于如何在Android中的TextView更改文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!