forum

Home / DeveloperSection / Forums / Android for loop not working in main thread

Android for loop not working in main thread

Anonymous User 2082 12-Nov-2014
I try to rotate image. i used runnable to rotate image,i wrote for loop and i want to rotate image inside for loop this is a my source

public void rotateimages(final View myView) {
    myHandler = new Handler();
    runnable = new Runnable() {
        @Override
        public void run() {
            double k = 30;
            double speed = Math.PI / k;
            for (alpa = 0; alpa < (Math.PI * 6 + res * 2 * Math.PI / 5); alpa += speed) {
                myView.setRotation((float) (myView.getRotation() - alpa));
                Log.e("alpa values", String.valueOf(alpa));
                k = Math.min(k + 0.2, 240);
                speed = Math.PI / k;
                myHandler.postDelayed(this, 100);
            }
            // rotateimages();
        }
    };
    myHandler.postDelayed(runnable, 180);
}

when i run my app i can rotate only one time.what is a wrong in my code? if anyone knows solution please help me


Updated on 13-Nov-2014
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By