how can i change an ImageView with a runOnUiThread
<p>I m trying to change the imageview everytime that a sound get finish so I ussed a runOnUIThread but the image just shows me the last image when the loop while that I put to change the images finish and below the code.</p>

<pre><code>public class PrincipalActivity extends ClassePai {

MediaPlayer avemarias,misterios;
ImageView imagem ;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_principal);

    avemarias = MediaPlayer.create(this, R.raw.teste);

    imagem = (ImageView) findViewById(id.imageViewGoz);



    while(contador&lt;3){

        mudaImagem(imagem,avemarias,misterios);

    }

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_principal, menu);
    return true;
}
</code></pre>

<p>}</p>

<pre><code>public class ClassePai extends Activity {
protected static int contador = 0;

protected void mudaImagem(final ImageView imagem,
        final MediaPlayer avemaria, final MediaPlayer misterios) {

    runOnUiThread(new Runnable() {

        @Override
        public void run() {


                if(contador &gt;= 0){

                    avemaria.start();
                }else if (contador == 11){

                    misterios.start();
                }else if (contador == 21){
                    misterios.start();
                }



                if (avemaria.isPlaying()||misterios.isPlaying()) {

                    imagem.setImageResource(com.willamydotcom.osantoterco.R.drawable.goz_quar+contador);



                while (avemaria.isPlaying()) {

                }
                    contador++;


                }


        }
    });

}
</code></pre>

<p>}</p>
