2016-05-31 45 views
0

我想在按鈕上顯示文本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

回答

-1

您可以使用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); 
} 
0

嘗試這樣

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