需要根据天气Code获取相应图片资源的ID,如何有效地简化?谢谢
/**
* Stupid Code!!!
*
* @
param code
* @
return */
private int getResourceId(int code) {
int resId = 0;
switch (code) {
case 3:
resId = R.drawable.ic_weather_3;
break;
case 4:
resId = R.drawable.ic_weather_4;
break;
case 5:
resId = R.drawable.ic_weather_5;
break;
case 6:
resId = R.drawable.ic_weather_6;
break;
case 7:
resId = R.drawable.ic_weather_7;
break;
case 8:
resId = R.drawable.ic_weather_8;
break;
case 9:
resId = R.drawable.ic_weather_9;
break;
case 10:
resId = R.drawable.ic_weather_10;
break;
case 11:
resId = R.drawable.ic_weather_11;
break;
case 12:
resId = R.drawable.ic_weather_12;
break;
case 13:
resId = R.drawable.ic_weather_13;
break;
case 14:
resId = R.drawable.ic_weather_14;
break;
case 15:
resId = R.drawable.ic_weather_15;
break;
case 16:
resId = R.drawable.ic_weather_16;
break;
case 17:
resId = R.drawable.ic_weather_17;
break;
case 18:
resId = R.drawable.ic_weather_18;
break;
case 19:
resId = R.drawable.ic_weather_19;
break;
case 20:
resId = R.drawable.ic_weather_20;
break;
case 21:
resId = R.drawable.ic_weather_21;
break;
case 22:
resId = R.drawable.ic_weather_22;
break;
case 23:
resId = R.drawable.ic_weather_23;
break;
case 26:
resId = R.drawable.ic_weather_26;
break;
case 27:
resId = R.drawable.ic_weather_27;
break;
case 28:
resId = R.drawable.ic_weather_28;
break;
case 29:
resId = R.drawable.ic_weather_29;
break;
case 30:
resId = R.drawable.ic_weather_30;
break;
case 31:
resId = R.drawable.ic_weather_31;
break;
case 32:
resId = R.drawable.ic_weather_32;
break;
case 33:
resId = R.drawable.ic_weather_33;
break;
case 34:
resId = R.drawable.ic_weather_34;
break;
case 35:
resId = R.drawable.ic_weather_35;
break;
case 36:
resId = R.drawable.ic_weather_36;
break;
case 37:
resId = R.drawable.ic_weather_37;
break;
case 38:
resId = R.drawable.ic_weather_38;
break;
case 39:
resId = R.drawable.ic_weather_39;
break;
case 40:
resId = R.drawable.ic_weather_40;
break;
case 41:
resId = R.drawable.ic_weather_41;
break;
case 42:
resId = R.drawable.ic_weather_42;
break;
case 43:
resId = R.drawable.ic_weather_43;
break;
case 44:
resId = R.drawable.ic_weather_44;
break;
case 45:
resId = R.drawable.ic_weather_45;
break;
case 46:
resId = R.drawable.ic_weather_46;
break;
case 47:
resId = R.drawable.ic_weather_47;
break;
default:
resId = R.drawable.ic_weather_3200;
break;
}
return resId;
}
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.