Pergunta

i want a number of images to be set as background one after another every few seconds. i asked how to do this and i got to know i should use handler().postDelayed() to perform that. i used to following code to implement what i wanted but it didnot work for me. i'm getting just one image and it is not changing at all.

new Handler().postDelayed(new Runnable() {
    public void run() {
        count += (count+1)%drawablearray.length;   
        rl.setBackgroundResource(drawablearray[count]);
           }
  }, 5000);

please help me if i'm wrong somewhere or tell me some other way to implement this. thanks in advance

Foi útil?

Solução

you have to repost your runnable:

Handler handler = new Handler();
handler.postDelayed(new Runnable() {
    public void run() {
        count += (count+1)%drawablearray.length;   
        rl.setBackgroundResource(drawablearray[count]);
        handler.postDelayed(this, 5000);   
        }
  }, 5000);
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top