1

I have a simple android app with a button who have the text HELLO. If i do not push this button after 10 seconds i want the text to be WAIT. Can someone help me? Thanks

Mitesh Jain
  • 673
  • 1
  • 7
  • 20
tinti
  • 1,455
  • 8
  • 23
  • 39

5 Answers5

1

check this timer task for 10 seconds ...button.setText("Wait...");

http://developer.android.com/resources/articles/timed-ui-updates.html

Samir Mangroliya
  • 39,918
  • 16
  • 117
  • 134
1

use this code

handler = new Handler(); 
handler.postDelayed(changeFunction(), 10*1000);

write above in onCreate()

private Runnable changeFunction(){ 
      t = new Timer();
      tt = new TimerTask() {              
          public void run() { 
              handler.postDelayed(changeFunction(), 10*1000);
              button.setText("WAIT");
          }          
      };          
    return tt;
    }
Matthias
  • 1,200
  • 2
  • 13
  • 33
RajaReddy PolamReddy
  • 22,428
  • 19
  • 115
  • 166
0

This should work

Timer buttonTimer                   =   new Timer();
final Runnable Timer_Tick = new Runnable() {
    public void run() {
    button.setText("WAIT");
}
};

buttonTimer.schedule(new TimerTask(){
    @Override
    public void run(){
        runOnUiThread(Timer_Tick);
    }
},10000);
blessanm86
  • 31,439
  • 14
  • 68
  • 79
0

You can use a timed handler message.

Button b;
boolean notPressed;
b.postDelayed(new Runnable() {

    @Override
    public void run() {
        if(notPressed){
            b.setText("Wait");
        }
    }
}, 10000);
Raz
  • 8,918
  • 3
  • 27
  • 40
0
Button b;
boolean notPressed;
b.postDelayed(new Runnable() {

    @Override
    public void run() {
        if(notPressed){
            b.setText("sexy");
        }
    }
}, 10000);
om252345
  • 2,395
  • 4
  • 29
  • 31