Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- final TextView textView = findViewById(R.id.text);
- final Button runOn = findViewById(R.id.runOn);
- runOn.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- new Thread() {
- public void run() {
- while (i++ < 1000) {
- try {
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- textView.setText("#" + i);
- }
- });
- Thread.sleep(300);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
- }.start();
- }
- });
- }
- private void runThread() {
- new Thread() {
- public void run() {
- while (i++ < 1000) {
- try {
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- textView.setText("#" + i);
- }
- });
- Thread.sleep(300);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
- }.start();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement