Suppose there is a String. It needs to be broken down into characters and each character separately with a slight delay between characters displayed on the screen in a parallel stream. That is, you need to achieve the effect of printing text.
The following code is written by a programmer by profession, but it does not work correctly. How to work with it or how to correct it in order to achieve the above result?
import java.util.Timer; ..... private final Handler mHandler = new Handler(); private Timer mTimer = new Timer(); private TextView tv3; .... class Task extends TimerTask { private string mData; private int k; public Task(String data){ mData = data; k=1; } public void run() { //Данный код выполяется каждые 5 секунд if(k<mData.length()){ handler.post(new Runnable(){ public void run() { //Вывод строки tv3.setText(mData.substring(0, k)); k++; } }); } else{ mTimer.cancel(); } } } ....Конструтор Activity{ .... tv3 = (TextView)findViewById(R.id.tv3); mTimer = new Timer(); //5000 - 5 секунд, str - строка для вывода String str = "Строчка"; mTimer.schedule(new Task(str), 5000); }
AsyncTask. - post_zeew