package hello.com;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.LinearLayout;
public class HelloWorldActivity extends Activity {
/** Called when the activity is first created. */
int [] images = new int [] {
R.drawable.ajax, R.drawable.java, R.drawable.ee, R.drawable.classic,
R.drawable.xml, };
int currentImage = 0 ;
@Override
public void onCreate(Bundle savedInstanceState) {
super .onCreate(savedInstanceState);
setContentView(R.layout.main);
LinearLayout mainLayout = (LinearLayout) findViewById(R.id.root);
final ImageView image = new ImageView( this );
mainLayout.addView(image);
image.setImageResource(images[ 0 ]);
image.setOnClickListener( new OnClickListener() {
@Override
public void onClick(View v) {
if (currentImage >= 4 ) {
currentImage = - 1 ;
}
image.setImageResource(images[++currentImage]);
}
});
}
}
|