Note that there are some explanatory texts on larger screens.

plurals
  1. POCalledFromWrongThreadException when trying to start animation from thread
    primarykey
    data
    text
    <p>I want to remove an object from a list and in the same time i want to animate to the user a fade out animation...</p> <p>The remove function create a <code>Thread</code>, in the thread i try to start the animation, but I'm getting that excetion:</p> <pre><code>android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views. </code></pre> <p>On the activity:</p> <pre><code>private Animation animation; private AnimationListener al; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.test); animation = AnimationUtils.loadAnimation(this, R.anim.fade_out); al = new AnimationListener() { public void onAnimationStart(Animation animation) { // do nothing } public void onAnimationRepeat(Animation animation) { // do nothing } public void onAnimationEnd(Animation animation) { TableRow tr = (TableRow) findViewById(R.id.test); tr.setVisibility(View.GONE); } }; animation.setAnimationListener(al); animation.reset(); } </code></pre> <p>When user will press the remove icon he will gets here:</p> <pre><code>public void remove(View v) { RemoveF rf = new RemoveF(); rf.start(); } </code></pre> <p>My Tread start here:</p> <pre><code>class RemoveF extends Thread { private boolean running; public void run() { running = true; try { do { //business logic goes here TableRow tr = (TableRow) findViewById(R.id.test); tr.setAnimation(animation); tr.startAnimation(animation); stopRunning(); try { Thread.sleep(1000); } catch (InterruptedException ie) { // do nothing } } while (running); } catch (Exception e) { Log.e("RemoveF", "Exception", e); } } public void stopRunning() { running = false; } } </code></pre> <p>Any idea how can i slove it? Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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