That is my code but it is not redrawing when I tell it to.
invalidate()
does not happen immediately when you call it. invalidate()
, like append()
and anything else involving the UI, puts a message on a message queue, that will be processed by the main application thread as soon as you let it. Since you are wasting the user's time in pointless sleep()
calls, plus doing flash I/O, in a loop on the main application thread, the main application thread cannot process the messages on the message queue. It will process all of your invalidate()
and append()
calls after your loop is over and you return control to Android from whatever callback you are in.
It is supposed to redraw after every line that is added to textview
No, it isn't.
but it still only redraws at the end?
Correct.
The simple solution is for you to get rid of the invalidate()
and the Thread.sleep(10)
and just load the entire file contents into your TextView
in one call.
The better solution is for you to read the whole file in via an AsyncTask
, then append the text to the TextView
in one call in onPostExecute()
. If needed, use a ProgressDialog
or something to keep the user entertained while this is going on.