在 while 循环中等待函数?

Wait funtion in a while cycle?

有什么方法可以在 Android Studio 中执行 wait() 函数吗?

function example ()
{
    while () 
    {
        //do something 
        //wait (x seconds) then go back
    }
}

你可以这样实现:

//in your method, use the Timer Schedule function:
new Timer().schedule(  
    new TimerTask() {
        @Override
        public void run() {
            //TODO: do something here of your interest.
        }
    },
    2000
);

这里我保留了2秒(2000毫秒)的延迟。您可以根据需要更改它。

 int interval = 3000;//milliseconds interval for delay
        new Handler().postDelayed(new Runnable() {


            @Override
            public void run() {


            }

            private void finish() {
                // TODO Auto-generated method stub

            }
        }, interval);