1

我正在制作一个内部包含许多图像的 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 个变量一切正常,上面的每个数量都不起作用。谢谢您的帮助

4

0 回答 0