Android Studio-用于处理程序线程的循环延迟

Android Studio-用于处理程序线程的循环延迟,android,multithreading,for-loop,delay,Android,Multithreading,For Loop,Delay,我试图使用处理程序线程设置一个带有延迟的for循环。但是,当我在for循环中设置处理程序线程时,我不能使用for循环的索引,因为它说它必须被称为final,但是这也不起作用。有人知道如何解决这个问题吗?我想你可以使用倒计时: new CountDownTimer(30000, 1000) { public void onTick(long millisUntilFinished) { mTextField.setText("seconds remaining: " +

我试图使用处理程序线程设置一个带有延迟的for循环。但是,当我在for循环中设置处理程序线程时,我不能使用for循环的索引,因为它说它必须被称为final,但是这也不起作用。有人知道如何解决这个问题吗?

我想你可以使用倒计时:

new CountDownTimer(30000, 1000) {

    public void onTick(long millisUntilFinished) {
        mTextField.setText("seconds remaining: " + millisUntilFinished / 1000);
       //here you can have your logic to set text to edittext
    }

    public void onFinish() {
        mTextField.setText("done!");
    }

}.start();

甚至像这样:

public void animateTextView(float initialValue, float finalValue, final TextView  textview) {

    ValueAnimator valueAnimator = ValueAnimator.ofFloat(initialValue, finalValue);
    valueAnimator.setDuration(1500);

    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {

            textview.setText(valueAnimator.getAnimatedValue().toString());

        }
    });
    valueAnimator.start();

}

要想
睡眠
线程
一段时间,您必须在
postdayed
之外设置循环,如下所示。这样,您就可以实现
循环的
索引

final ImageButton[] all= {btn1, btn2, btn3, btn4};
Handler handler1 = new Handler();
for (int a = 1; a<= all.length ;a++) {
    handler1.postDelayed(new Runnable() {

         @Override
         public void run() {

             //Here..
         }
         }, 1000 * a);
    } 
}
final ImageButton[]all={btn1,btn2,btn3,btn4};
Handler handler1=新的Handler();

对于(int a=1;请在此处添加代码以获得更好的帮助。。。