Change Button Text on Android

2019-06-07 16:51发布

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

5条回答
可以哭但决不认输i
2楼-- · 2019-06-07 16:55

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);
查看更多
Fickle 薄情
3楼-- · 2019-06-07 16:59

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;
    }
查看更多
倾城 Initia
4楼-- · 2019-06-07 17:00

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);
查看更多
Evening l夕情丶
5楼-- · 2019-06-07 17:03
Button b;
boolean notPressed;
b.postDelayed(new Runnable() {

    @Override
    public void run() {
        if(notPressed){
            b.setText("sexy");
        }
    }
}, 10000);
查看更多
劫难
6楼-- · 2019-06-07 17:10

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

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

查看更多
登录 后发表回答