0

我尝试使用按钮更新我的 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] il 加载 ic_launcher 而不是 ecran6 并且图像[6] 什么也不加载

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

感谢帮助

4

1 回答 1

1

只是猜测(您的条件错误)使用:

if(type == 0){
    if(ecran != 0){ //min is 0
        ecran--;
    }
}
else if(type == 1){
    if(ecran != nbEcrans-1){ //max is nbEcrans-1
        ecran++;
    }
}
于 2013-01-30T17:49:00.863 回答