Pebble time refresh UI card contents without calling new card

107 views Asked by At

so I have this simple code:

var UI = require('ui');

var numero = 1;

setInterval(function(){ 
var main = new UI.Card({ body: numero });
   numero++;
   main.show();
  }, 1000);

I want to do the same without calling a new card, how can I do this? In a simpler way

1

There are 1 answers

0
dybm On

This is what you want:

var UI = require('ui');

var numero = 1;
var main = new UI.Card({ body: numero });
main.show();

setInterval(function(){ 
  main.body(numero);
  numero++;
  }, 1000);

In your original code, every time setInterval would run you would define a new card and display it on top of whatever was already displayed. What you want to do instead is define the card first, then on each successive iteration you can update that one card's body.

Notice that you do not need to have main.show(); to update the display. By changing the body text, the display is updated.