java - Android for loop not working in main thread -
java - Android for loop not working in main thread -
i seek rotate image. used runnable rotate image,i wrote loop , want rotate image within loop 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; (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 run app can rotate 1 time.what wrong in code? if knows solution please help me
if want loop , need define 'runnable' loop 1 time again edit code to:
myhandler = new handler(); count = 0; public void rotateimage(final view myview, final int size) { runnable = new runnable() { @override public void run() { count++; myview.setrotation(myview.getrotation() + size); if(count == 10){ myhandler.removecallback(runnable ); } myhandler.postdelayed(this, 1000); // 1000 means 1 sec duration } }; myhandler.postdelayed(runnable, 180); // 180 delay after new runnable going called }
how loop itself, that's mean 1 code line, or 1 statement phone call event again. example:
void nothing(int a){ if(a> 0) nothing(a-1); }
and phone call nothing(10). that's all, , avoid action like:
void nothing(int a){ for(int =0; i< a;i++) nothing(a-1); //big wrong } know solution?
java android for-loop rotation
Comments
Post a Comment