Change button text on Android

I have a simple Android app with a button that has the text HELLO. If I do not press this button after 10 seconds, I want the text to be WAIT. Can anybody help me? Thanks

+1
source share
5 answers

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; } 
+1
source

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

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

+1
source

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); 
0
source

You can use a time handler message.

 Button b; boolean notPressed; b.postDelayed(new Runnable() { @Override public void run() { if(notPressed){ b.setText("Wait"); } } }, 10000); 
0
source
 Button b; boolean notPressed; b.postDelayed(new Runnable() { @Override public void run() { if(notPressed){ b.setText("sexy"); } } }, 10000); 
0
source

Source: https://habr.com/ru/post/1398790/


All Articles