Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 使用计时器更改按钮文本_Android_Timer - Fatal编程技术网

Android 使用计时器更改按钮文本

Android 使用计时器更改按钮文本,android,timer,Android,Timer,我想在按钮上显示文本3秒钟,然后用另一个单词更改按钮文本。我怎么能做到? 我使用了这些代码,但刚刚看到第二个文本 public void TimePause () { int Time_1 = (Calendar.getInstance()).get(Calendar.SECOND)+3; while ( ((Calendar.getInstance()).get(Calendar.SECOND)) != Time_1 ) { } } if (tasbiha

我想在按钮上显示文本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");
}
您可以使用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

这是因为tasbihat的价值观。如果tasbihat==0,则在此处比较=0,如果tasbihat=33,则在中比较;看看这个。使用Handler延迟任何事情@Pravin谢谢你的回答,但这是我代码的一部分;当你的任务下一次完成时,它将进入你的if条件,正确地格式化你的代码,并且只使用英语。