Android 'setText' for X seconds

0

In my activity I call a setText :

   tvdato.setText(String.valueOf("BIEN"));

I would like to know a method to make it provisional, that is, to last for a few seconds drawn on the screen.

    
asked by PiledroMurcia 22.05.2017 в 10:12
source

1 answer

2

You can make your TextView invisible when you spend a few seconds with the help of TimerTask :

Timer t = new Timer(false);
t.schedule(new TimerTask() {
@Override
public void run() {
     runOnUiThread(new Runnable() {
          public void run() {
              tvdato.setVisibility(View.INVISIBLE);
          }
      });
  }
}, 5000); //5000 equivale a 5 segundos (en milisegundos)

On the other hand, I think the most useful thing to show a message for a few seconds on the screen, is to use a Toast :

Toast toast1 = Toast.makeText(getApplicationContext(),"BIEN", Toast.LENGTH_SHORT).show();
    
answered by 22.05.2017 / 10:15
source