You cannot use things in the user interface thread from the background. So this call:
iv.setImageResource(mThumbIds[i]);
Must be done in the main thread. In fact, you probably don't need the background thread to get the effect you're looking for. You can do it simply as an action, no runnable needed. and then do something like this:
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); iv = (ImageView) findViewById(R.id.yourImageViewID); int i = 0; Runnable r = Runnable(){ public void run(){ iv.setImageResource(mThumbIds[i]); i++; if(i >= mThumbIds.length){ i = 0; } iv.postDelayed(r, 3000);
Foamyguy
source share