如何在 Android TextView 中更改文本 [英] how to change text in Android TextView

查看:16
本文介绍了如何在 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");

但由于某种原因,我运行它时只显示第二个文本.我认为这可能与 Thread.sleep() 方法阻塞有关.那么有人可以告诉我如何异步"实现计时器吗?

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-discuss google 群里发了这个答案

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

sadboy 给出的可运行示例

Runnable example sadboy gave

祝你好运

这篇关于如何在 Android TextView 中更改文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆