在100毫秒后向TextField添加字母



我试图将特定字符串中的字母附加到TextField上。这是我目前所尝试的。但是运气不好。

这里发生的事情是等待100毫秒,然后直接显示字符串

outConsole = (TextView) findViewById(R.id.outconsole); 
    int i, j;
    String fin = ""; 
    final String in = "HELLO!"; 
    i = in.length;
    try{
    for(j = 0; j < i; j++){
        Thread.sleep(100);
        fin = fin + in.charAt(j); 
        outConsole.setText(fin);  
    }
    }catch(Exception e){}
}

我如何做到这一点?

我想要这样的东西,但慢一点:https://www.youtube.com/watch?v=Ff-eDOGLuYw

尝试使用处理程序。像这样的代码应该可以工作:

Handler handler = new Handler();    
Runnable runnable = new Runnable() {
@Override
public void run() {
  //update your ui
  handler.postDelayed(this, 100);//this restarts the handler better to have some terminating condition
}
};
handler.postDelayed(runnable, 100);//starts the handler first time

最新更新