-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSimple-TypewriterForAndroid
More file actions
46 lines (39 loc) · 961 Bytes
/
Simple-TypewriterForAndroid
File metadata and controls
46 lines (39 loc) · 961 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package com.example.typewriter;
import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.TextView;
public class MainActivity extends Activity {
TextView tv;
String str = "some words !!!";
int i = 0;
Timer timer = new Timer();
Handler handler = new Handler() {
public void handleMessage(Message msg) {
tv.append(msg.obj.toString());
};
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv = (TextView) findViewById(R.id.tv);
timer.schedule(new TimerTask() {
@Override
public void run() {
Message msg = new Message();
char[] c = str.toCharArray();
msg.obj = c[i];
handler.sendMessage(msg);
if (i < c.length - 1) {
++i;
} else {
this.cancel();
}
}
}, 0, 1000);
}
}