android的ImageView点击换图
布局了一个ImageVIew的控件后,java的代码如下,运行后一片空白,请问哪里错了?publicclassActivity1extendsActivity{int[]...
布局了一个ImageVIew的控件后,java的代码如下,运行后一片空白,请问哪里错了?
public class Activity1 extends Activity {
int[] images= new int[]{
R.drawable.chun,
R.drawable.xia,
R.drawable.qiu,
R.drawable.dong,
};
int current=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final ImageView iv=(ImageView) findViewById(R.id.imageView1);
iv.setImageResource(images[0]);
iv.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
iv.setImageResource(images[++current % images.length]);
}
});
}
} 展开
public class Activity1 extends Activity {
int[] images= new int[]{
R.drawable.chun,
R.drawable.xia,
R.drawable.qiu,
R.drawable.dong,
};
int current=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final ImageView iv=(ImageView) findViewById(R.id.imageView1);
iv.setImageResource(images[0]);
iv.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
iv.setImageResource(images[++current % images.length]);
}
});
}
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询