문제

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

도움이 되었습니까?

해결책

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);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top