图像背景改变的ifs太多了?

时间:2012-08-24 11:59:05

标签: android image if-statement background many-to-many

我正在制作一款内置多张图片的Android应用。由于我从共享首选项中读取的变量,我必须更改我的应用程序内的30个图像的背景。它看起来像(只有一部分女巫背景改变,我写“findviewvbyid”并阅读共享偏好数据:

if (fav[0]==0) s0.setImageResource(R.drawable.stara); else s0.setImageResource(R.drawable.star);
        if (fav[1]==0) s1.setImageResource(R.drawable.stara); else s1.setImageResource(R.drawable.star);
        if (fav[2]==0) s2.setImageResource(R.drawable.stara); else s2.setImageResource(R.drawable.star);
        if (fav[3]==0) s3.setImageResource(R.drawable.stara); else s3.setImageResource(R.drawable.star);
        if (fav[4]==0) s4.setImageResource(R.drawable.stara); else s4.setImageResource(R.drawable.star);
        if (fav[5]==0) s5.setImageResource(R.drawable.stara); else s5.setImageResource(R.drawable.star);
        if (fav[6]==0) s6.setImageResource(R.drawable.stara); else s6.setImageResource(R.drawable.star);
        if (fav[7]==0) s7.setImageResource(R.drawable.stara); else s7.setImageResource(R.drawable.star);
        if (fav[8]==0) s8.setImageResource(R.drawable.stara); else s8.setImageResource(R.drawable.star);
        if (fav[9]==0) s9.setImageResource(R.drawable.stara); else s9.setImageResource(R.drawable.star);    
if (fav[10]==0) s0.setImageResource(R.drawable.stara); else s0.setImageResource(R.drawable.star);
        if (fav[11]==0) s1.setImageResource(R.drawable.stara); else s1.setImageResource(R.drawable.star);
        if (fav[12]==0) s2.setImageResource(R.drawable.stara); else s2.setImageResource(R.drawable.star);
        if (fav[13]==0) s3.setImageResource(R.drawable.stara); else s3.setImageResource(R.drawable.star);
        if (fav[14]==0) s4.setImageResource(R.drawable.stara); else s4.setImageResource(R.drawable.star);
        if (fav[15]==0) s5.setImageResource(R.drawable.stara); else s5.setImageResource(R.drawable.star);
        if (fav[16]==0) s6.setImageResource(R.drawable.stara); else s6.setImageResource(R.drawable.star);
        if (fav[17]==0) s7.setImageResource(R.drawable.stara); else s7.setImageResource(R.drawable.star);
        if (fav[18]==0) s8.setImageResource(R.drawable.stara); else s8.setImageResource(R.drawable.star);
        if (fav[19]==0) s9.setImageResource(R.drawable.stara); else s9.setImageResource(R.drawable.star);
        if (fav[20]==0) s0.setImageResource(R.drawable.stara); else s0.setImageResource(R.drawable.star);
        if (fav[21]==0) s1.setImageResource(R.drawable.stara); else s1.setImageResource(R.drawable.star);
        if (fav[22]==0) s2.setImageResource(R.drawable.stara); else s2.setImageResource(R.drawable.star);
        if (fav[23]==0) s3.setImageResource(R.drawable.stara); else s3.setImageResource(R.drawable.star);
        if (fav[24]==0) s4.setImageResource(R.drawable.stara); else s4.setImageResource(R.drawable.star);
        if (fav[25]==0) s5.setImageResource(R.drawable.stara); else s5.setImageResource(R.drawable.star);
        if (fav[26]==0) s6.setImageResource(R.drawable.stara); else s6.setImageResource(R.drawable.star);
        if (fav[27]==0) s7.setImageResource(R.drawable.stara); else s7.setImageResource(R.drawable.star);
        if (fav[28]==0) s8.setImageResource(R.drawable.stara); else s8.setImageResource(R.drawable.star);
        if (fav[29]==0) s9.setImageResource(R.drawable.stara); else s9.setImageResource(R.drawable.star);
        if (fav[30]==0) s9.setImageResource(R.drawable.stara); else s9.setImageResource(R.drawable.star);

我注意到10个变量一切正常,上面的每个数量都不起作用。谢谢你的帮助

0 个答案:

没有答案