package com.xh.handlerdemo;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.os.Handler;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ImageView;
public class MainActivity extends ActionBarActivity {
private ImageView imageView;
private int images[]={R.drawable.p1,R.drawable.p2,R.drawable.p3,R.drawable.p10,R.drawable.p11,R.drawable.p12,R.drawable.p13,
R.drawable.p18,R.drawable.p14,R.drawable.p17,R.drawable.p19,R.drawable.p20};
private int index;
private MyRunnable myRunnable=new MyRunnable();
private Handler handler=new Handler();
class MyRunnable implements Runnable{
@Override
public void run() {
index++;
index=index%12;
imageView.setImageResource(images[index]);
handler.postDelayed(myRunnable, 1000);
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView=(ImageView) findViewById(R.id.imageView1);
handler.postDelayed(myRunnable, 1000);
}
}
源代码下载地址:http://download.csdn.net/detail/duguiminer/8717499