更新imageView不是好的

时间:2013-01-30 17:41:25

标签: android image

我尝试使用按钮

更新我的imageiew
private void visitUpdateImage(int type) {

if(type == 0){
    if(ecran != 1){
        ecran--;
    }
}
else if(type == 1){
    if(ecran != nbEcrans){
        ecran++;
    }
}

int[] images = new int[nbEcrans];
images[0] = R.drawable.ecran1;
images[1] = R.drawable.ecran2;
images[2] = R.drawable.ecran3;
images[3] = R.drawable.ecran4;
images[4] = R.drawable.ecran5;
images[5] = R.drawable.ecran6;
images[6] = R.drawable.ecran7;

ImageView image = (ImageView) findViewById(R.id.imageView);

image.setImageResource(images[ecran - 1]);

System.out.println(ecran);

}

开始很好但是图像[5]加载ic_launcher而不是ecran6而图像[6]加载

我在所有可绘制的存储库中都有我的所有ecrans

感谢您的帮助

1 个答案:

答案 0 :(得分:1)

猜测(你的条件有误)使用:

if(type == 0){
    if(ecran != 0){ //min is 0
        ecran--;
    }
}
else if(type == 1){
    if(ecran != nbEcrans-1){ //max is nbEcrans-1
        ecran++;
    }
}