I want the Text in a TextView to be displayed word after word or even letter after letter, just like in most rpgs and adventures with textboxes. A good example how the textflow should look like is the game phoenix wright ( http://youtu.be/2OOX2Gv0768?t=1m7s )
What i have tried until now is this:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String text = "test test test test";
String[] split = text.split(" ");
Deque<String> words = new LinkedList<String>();
for (int i = 0; i<split.length; i++)
{
words.addLast(split[i]);
}
showNextWord(words);
}
public void showNextWord(final Deque<String> words)
{
Handler handler = new Handler();
handler.postDelayed(new Runnable()
{
public void run()
{
TextView t = (TextView) findViewById(R.id.textBox);
t.append(words.pollFirst()+" ");
if (words.size()>0)
showNextWord(words);
}
}, 500);
}
I tested on an emulator and it seems to be with low performance, even more if i would start a delay after displaying each letter. The delay isn´t consistent.
In addition to that I hope there is a more elegant solution to that. Maybe some way to be more flexible with the delays? E.g. a bigger delay after a sentence and so on.
Thank you very much!