Note that there are some explanatory texts on larger screens.

plurals
  1. PORun animation in ViewFlipper to flip images when button click more than one time
    text
    copied!<p>I'm working on LCR dice game in Android and I have a problem,when I try to click again on a button to run image flip animation,I'm using <code>Asynctask</code> to run animation this is a sample code of my project:</p> <pre><code>public class FlippingImage extends AsyncTask&lt;Void, Long, Long&gt; { @Override protected Long doInBackground(Void... params) { // TODO Auto-generated method stub int timer=0; mp=MediaPlayer.create(LCRDiceActivity.this,R.raw.rollingdices); mp.start(); while (timer&lt;5000) { mp.start(); Log.i("LCRgame", "start flip"); mFlipper.startFlipping(); mFlipper.setInAnimation(AnimationUtils.loadAnimation(LCRDiceActivity.this, R.anim.push_up_in)); mFlipper.setOutAnimation(AnimationUtils.loadAnimation(LCRDiceActivity.this, R.anim.push_up_out)); mFlipper2.startFlipping(); mFlipper2.setInAnimation(AnimationUtils.loadAnimation(LCRDiceActivity.this, R.anim.push_up_in)); mFlipper2.setOutAnimation(AnimationUtils.loadAnimation(LCRDiceActivity.this, R.anim.push_up_out)); mFlipper3.startFlipping(); mFlipper3.setInAnimation(AnimationUtils.loadAnimation(LCRDiceActivity.this, R.anim.push_up_in)); mFlipper3.setOutAnimation(AnimationUtils.loadAnimation(LCRDiceActivity.this, R.anim.push_up_out)); SystemClock.sleep(1000); timer=timer+1000; } return null; } @Override protected void onProgressUpdate(Long... values) { // TODO Auto-generated method stub super.onProgressUpdate(values); LCRDiceActivity.this.ChipsCountPlayer1.setText(ChipsCount1); } @Override protected void onPostExecute(Long result) { // TODO Auto-generated method stub //mFlipper.stopFlipping(); Random myRondom=new Random(); int myNumber=myRondom.nextInt(5)+1; switch (myNumber) { case 1: mFlipper.setDisplayedChild(mFlipper.indexOfChild(findViewById(R.id.img_L_1))); ChipsCount1=ChipsCount1-1; break; case 2: mFlipper.setDisplayedChild(mFlipper.indexOfChild(findViewById(R.id.img_C_1))); ChipsCount1=ChipsCount1-1; break; case 3: mFlipper.setDisplayedChild(mFlipper.indexOfChild(findViewById(R.id.img_R_1))); ChipsCount1=ChipsCount1-1; break; case 4: mFlipper.setDisplayedChild(mFlipper.indexOfChild(findViewById(R.id.img_dot_1))); break; case 5: mFlipper.setDisplayedChild(mFlipper.indexOfChild(findViewById(R.id.img_dot_1))); break; case 6: mFlipper.setDisplayedChild(mFlipper.indexOfChild(findViewById(R.id.img_dot_1))); break; default: break; } </code></pre> <p>}</p> <h3>And this is buttonClickListener :</h3> <pre><code>private OnClickListener StartClickListener=new OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub // flipImage=new FlippingImage(); // flipImage.execute( ); Runnable myRunner = new Runnable(){ public void run() { new FlippingImage().execute(); }}; myHandler=new Handler(); myHandler.post(myRunner); } }; </code></pre> <h3>And I got this error:</h3> <pre><code>11-21 14:16:25.861: ERROR/AndroidRuntime(329): FATAL EXCEPTION: AsyncTask #2 11-21 14:16:25.861: ERROR/AndroidRuntime(329): java.lang.RuntimeException: An error occured while executing doInBackground() 11-21 14:16:25.861: ERROR/AndroidRuntime(329):at android.os.AsyncTask$3.done(AsyncTask.java:200) 11-21 14:16:25.861: ERROR/AndroidRuntime(329):at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274) 11-21 14:16:25.861: ERROR/AndroidRuntime(329):at java.util.concurrent.FutureTask.setException(FutureTask.java:125) 11-21 14:16:25.861: ERROR/AndroidRuntime(329):at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308) 11-21 14:16:25.861: ERROR/AndroidRuntime(329):at java.util.concurrent.FutureTask.run(FutureTask.java:138) 11-21 14:16:25.861: ERROR/AndroidRuntime(329):at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088) 11-21 14:16:25.861: ERROR/AndroidRuntime(329):at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581) 11-21 14:16:25.861: ERROR/AndroidRuntime(329):at java.lang.Thread.run(Thread.java:1019) 11-21 14:16:25.861: ERROR/AndroidRuntime(329): Caused by: android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views. 11-21 14:16:25.861: ERROR/AndroidRuntime(329):at android.view.ViewRoot.checkThread(ViewRoot.java:2932) 11-21 14:16:25.861: ERROR/AndroidRuntime(329):at android.view.ViewRoot.invalidateChild(ViewRoot.java:642) 11-21 14:16:25.861: ERROR/AndroidRuntime(329):at android.view.ViewRoot.invalidateChildInParent(ViewRoot.java:668) 11-21 14:16:25.861: ERROR/AndroidRuntime(329):at android.view.ViewGroup.invalidateChild(ViewGroup.java:2511) </code></pre> <p>How to solve this problem please help me ?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload