0

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("word one");
     checkPoint = 1;
     EndViber.vibrate(500);
     // pause 
     TimePause();
     tasbihat = 33;
     //text two
     counter.setText("33");
     swZekrtxt.setText("word two");
}
Willi Mentzel
  • 27,862
  • 20
  • 113
  • 121
dariush
  • 41
  • 4

2 Answers2

0

Try like this

    Timer t=new Timer();
    TimerTask task=new TimerTask() {
        @Override
        public void run() {
          button.setText("");//Example
        }
    };
    t.scheduleAtFixedRate(task,0,3000);//3 seconds
akhil Rao
  • 1,169
  • 7
  • 17
-1

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);
}
Alexander
  • 857
  • 6
  • 10