用定时器更改按钮文本

问题描述:

我想在按钮上显示文本3秒,然后用另一个字改变按钮文本。我怎么能做到这一点? 我使用这些代码,但只看到第二个文本。用定时器更改按钮文本

public void TimePause() 
{ 
    int Time_1 = (Calendar.getInstance()).get(Calendar.SECOND)+3; 
    while (((Calendar.getInstance()).get(Calendar.SECOND)) != Time_1) 
    { 

    } 
} 


if (tasbihat==0) 
{ 
    //text one 
    counter.setText("word one"); 
    checkPoint = 1; 
    EndViber.vibrate(500); 
    // pause 
    TimePause(); 
    tasbihat = 33; 
    //text two 
    counter.setText("33"); 
    swZekrtxt.setText("word two"); 
} 
+0

因为tasbihat价值启示。如果(tasbihat == 0)你在这里比较= 0,如果tasbihat = 33; – Pavya

+0

看看这个。使用处理程序延迟任何东西http://stackoverflow.com/questions/6700802/android-timer-updating-a-textview-ui/6702767#6702767 –

+0

@Pravin谢谢你的回答,但这些都是我的代码的一部分。 – dariush

您可以使用Handler。不要忘记在使用前初始化mButton

private Button mButton; 
private void changeTextButton() { 
    int delayTime = 3000; // 3 sec 
    mButton.postDelayed(new Runnable() { 
     @Override 
     public void run() { 
      mButton.setText("Some text"); 
     } 
    }, delayTime); 
} 

尝试这样

Timer t=new Timer(); 
    TimerTask task=new TimerTask() { 
     @Override 
     public void run() { 
      button.setText("");//Example 
     } 
    }; 
    t.scheduleAtFixedRate(task,0,3000);//3 seconds