BufferedReader hl = new BufferedReader(new InputStreamReader(getResources().openRawResource(R.raw.lines)));
while(hl.ready()){
showL
That is bacause your invalidate() is in a thread while loop and is being acummulated, so to speak, until the loop ends, and only than it draws...
I had the same problem when using Thread.sleep() within a loop. You can use a post delayed method to draw each line, which in this case is one line per second:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
BufferedReader hl = new BufferedReader(new InputStreamReader(getResources().openRawResource(R.raw.text)));
TextView showLines = (TextView) findViewById(R.id.textView1);
appendLines(hl, showLines);
}
public void appendLines(final BufferedReader br, final TextView tv){
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
try {
if(br.ready()){
try {
tv.append(br.readLine()+"\n");
} catch (IOException e) {
e.printStackTrace();
}
tv.invalidate();
appendLines(br, tv);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}, 1000);
}