Android newb here. Please use small words 🙂
I’d like to simulate typewriter output on my Android. The output being displayed is generated by a game and is somewhat freeform. The effect I want to see individual characters appear at a rate of about 6 characters a second. When a ‘carriage return’ is seen, I’d like to insert a delay then resume typing on the left.
What are some suggestions on views? Would the view of choice for this be a TextView? Even that seems like overkill for this read-only coarsely scrolling output.
I saw something on this thread about an AsyncTask. That looks useful. Perhaps my game will write to some manner of buffer, and a subclass of AsyncTask will pull a character out every .15 seconds or so, add it to the TextView, then invalidate() the TextView? Sound like a plan?
Resolution:
I wrapped the TextView in the ScrollView and it worked fine. The suggested ‘TextView.append()’ also did the job, as expected. I had trouble with the scroll.FullScroll(), however. Apparently this has to be executed using a Runnable from the scroll.post() method. I don’t know why, exactly, but I’ll dig into that later. There are a number of SO threads about it.
A
TextViewwrapped in aScrollViewseems likely:You do not need an
AsyncTaskfor this. UsepostDelayed()on yourTextViewor something to schedule aRunnableto run in 166 milliseconds. ThatRunnablewill:TextViewScrollViewto the bottom (in case you have exceeded what fits on the screen)postDelayed()to run in another 166 millisecondsThe first two bullets would look like:
Things will not be completely even, as that 166ms is a minimum time before the
Runnableruns. OTOH, slightly irregular delivery of keys would accentuate the typewriter effect.