Question

I have this for loop:

for(int i = 1 ; i <= right_num ; i++ ){
    for(int u = 1 ; u <= left_num ; u++ ){
        int resourceId = this.getResources().getIdentifier("c"+u+"_r"+i, "id", this.getPackageName());
        ImageButton imageButton = (ImageButton) findViewById(resourceId);
        imageButton.setBackgroundResource(R.drawable.white_circle);
    }
}

and i want to convert it to a Timer Schedule , and set the time between changes 250 ms.

how to do this ?

Était-ce utile?

La solution

Try this:

int i=0;
int total_time=250*left_num*right_num;
private CountDownTimer counter = new CountDownTimer(total_time, 250) {

        public void onTick(long millisUntilFinished) {
            int u=i%left_num+1,v=i/left_num+1;
            int resourceId = this.getResources().getIdentifier("c"+u+"_r"+v, "id", this.getPackageName());
            ImageButton imageButton = (ImageButton) findViewById(resourceId);
            imageButton.setBackgroundResource(R.drawable.white_circle);
            i++;
        }

        public void onFinish() {

        }
    };

Let me know if it helps

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top