How to set timer in android?

后端 未结 21 941
渐次进展
渐次进展 2020-11-22 00:51

Can someone give a simple example of updating a textfield every second or so?

I want to make a flying ball and need to calculate/update the ball coordinates every se

21条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-22 01:43

    I use this way:

    String[] array={
           "man","for","think"
    }; int j;
    

    then below the onCreate

    TextView t = findViewById(R.id.textView);
    
        new CountDownTimer(5000,1000) {
    
            @Override
            public void onTick(long millisUntilFinished) {}
    
            @Override
            public void onFinish() {
                t.setText("I "+array[j] +" You");
                j++;
                if(j== array.length-1) j=0;
                start();
            }
        }.start();
    

    it's easy way to solve this problem.

提交回复
热议问题