Advertisement
Sketchware

No onCreate com um button mostra os segundos passando

Jan 12th, 2023
893
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.50 KB | None | 0 0
  1. final EditText editText = (EditText) findViewById(R.id.editText1);
  2.  
  3. Timer timer = new Timer();
  4. timer.scheduleAtFixedRate(new TimerTask() {
  5.     @Override
  6.     public void run() {
  7.         Calendar c = Calendar.getInstance();
  8.         int seconds = c.get(Calendar.SECOND);
  9.         final String time = String.valueOf(seconds);
  10.         runOnUiThread(new Runnable() {
  11.             @Override
  12.             public void run() {
  13.                 editText.setText(time);
  14.             }
  15.         });
  16.     }
  17. }, 0, 1000);
  18.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement