package com.example.helloword;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
public class hello extends Activity {
int [] images =new int[]{
R.drawable.aaa,
R.drawable.bb,
};
int currentImg=0;
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LinearLayout main=(LinearLayout) findViewById(R.id.root);
ImageView image =new ImageView(this);
image.setImageResource(images[0]);
main.addView(image);
image.setOnClickListener(new OnClickListener(){
public void onClick(View v){
image.setImageResource(images[++currentImg%images.length]);
}
});
}
}
用下我修改后的