Appending a scrolling textview in timed increments

359 views Asked by At

I've created a scrolling textview and have been able to add text and scroll just fine. The thing is, I'm trying to add text at timed intervals and said interval can be adjusted by the user by hitting one of two buttons at the bottom of the screen. Everything is in place, but no matter what I do, I can only get it to display all of the text at once after the whole duration. Say I'm trying to add text every half second for ten seconds. Running it results in nothing for ten seconds, and then everything shows up. I've tried for/while loops with counters and keeping track via system time. Nope. Recursion blows the stack in no time, which wasn't much of a surprise. Using wait() or Thread.sleep() don't work and wouldn't be ideal anyway as the buttons need to be live at all times. Making a separate thread in a private inner class didn't work as you can't touch Views created in another thread. Trying to create a custom View in separate thread refused to work for reasons I can't figure out just yet.

How in the heck would I do this so each entry is added in real time?

1

There are 1 answers

0
gauravD On

In My case It works Fine for Autoscroling along with one Timer object

timer=new Timer();
scroll.setSmoothScrollingEnabled(true);
scroll.pageScroll(ScrollView.FOCUS_DOWN);
scroll.smoothScrollTo(0, text.getBaseline());
x=text.getBaseline();
Toast.makeText(scoruby.this,"number"+x++, Toast.LENGTH_SHORT).show();

timer.schedule(new TimerTask() {

@Override
public void run() {
    TimerMethod();


}
}, 0,1000);
}
private void TimerMethod()
{
//This method is called directly by the timer
//and runs in the same thread as the timer.

//We call the method that will work with the UI
//through the runOnUiThread method.
this.runOnUiThread(Timer_Tick);
}

private Runnable Timer_Tick = new Runnable() {
public void run() {
    x+=5;
    scroll.smoothScrollTo(0, x++);  



}
};