RWillamy
RWillamy

Reputation: 53

SetImageResource() do not just works at the second time in a loop

Well! I made a code that set a new imageView each time the sound ends and I verify it with a While loop the it just works at the second time. I already tried with a switch but it didnt works.

av = MediaPlayer.create(this,R.raw.ave_maria);
    av.start();

    salve = MediaPlayer.create(this,R.raw.salve_rainha);

    im = (ImageView) findViewById(R.id.imag1);

    Thread thread = new Thread() {
        public void run() {

            while (true) {
                // YouActivity
                GozososActivity.this.runOnUiThread(new Runnable() {

                    public void run() {
                        if (av.isPlaying()) {

                        } else {
                            avemarias++;
                            if(avemarias > 10){
                                salve.start();
                            }else{
                                im.setImageResource(R.drawable.primeiro_misterio_gozoso+avemarias);

                                av.start();             
                            }
                        }
                    }
                });
            }
        }
    };
    thread.start();

Upvotes: 0

Views: 410

Answers (1)

user370305
user370305

Reputation: 109237

Look at your code line,

im.setImageResource(R.drawable.primeiro_misterio_gozoso+avemarias);

You are doing some of two integer numbers.

So is there any resource available for that number? (Look in R.java file if not then the method does not work)

For setImageResource() Android only set the resource as drawable which has int entry in R.java or in android.R file.

Upvotes: 1

Related Questions