【发布时间】:2011-10-18 10:11:57
【问题描述】:
我有一个简单的 android 应用程序,带有一个带有文本 HELLO 的按钮。 如果我在 10 秒后不按此按钮,我希望文本等待。 有人能帮我吗? 谢谢
【问题讨论】:
-
因为你必须使用定时器......通过使用定时器你可以设置按钮文本等待 10 秒后.....
我有一个简单的 android 应用程序,带有一个带有文本 HELLO 的按钮。 如果我在 10 秒后不按此按钮,我希望文本等待。 有人能帮我吗? 谢谢
【问题讨论】:
使用此代码
handler = new Handler();
handler.postDelayed(changeFunction(), 10*1000);
上面写在onCreate()中
private Runnable changeFunction(){
t = new Timer();
tt = new TimerTask() {
public void run() {
handler.postDelayed(changeFunction(), 10*1000);
button.setText("WAIT");
}
};
return tt;
}
【讨论】:
检查这个定时器任务 10 秒 ...button.setText("Wait...");
http://developer.android.com/resources/articles/timed-ui-updates.html
【讨论】:
这应该可以工作
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);
【讨论】:
您可以使用定时处理程序消息。
Button b;
boolean notPressed;
b.postDelayed(new Runnable() {
@Override
public void run() {
if(notPressed){
b.setText("Wait");
}
}
}, 10000);
【讨论】:
Button b;
boolean notPressed;
b.postDelayed(new Runnable() {
@Override
public void run() {
if(notPressed){
b.setText("sexy");
}
}
}, 10000);
【讨论】: