dariush dariush - 6 months ago 9
Android Question

Change Button text with a timer

I want to show a text on button for 3 seconds and after that change the button text with another word. how i can do this?
i used these codes but just seen the second text.

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("ٱلْحَمْدُ لِلَّهِ");
checkPoint = 1;
EndViber.vibrate(500);
// pasue
TimePause();
tasbihat = 33;
//text two
counter.setText("33");
swZekrtxt.setText("ٱلْحَمْدُ لِلَّهِ");
}

Answer

You can use Handler. Don't forget initialize mButton before using.

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