0
public String getDay() {
if (getDay().equals("Mon")){
int weatherIconImageResource = getResources().getIdentifier("icon_" + condition.getCode(), "drawable", getPackageName());
} else if (getDay().equals("Sun")){
int weatherIconImageResource = getResources().getIdentifier("icon_" + condition.getCode(), "drawable", getPackageName());
} else if (getDay().equals("Tue")){
int weatherIconImageResource = getResources().getIdentifier("icon_" + condition.getCode(), "drawable", getPackageName());
} else if (getDay().equals("Wed")){
int weatherIconImageResource = getResources().getIdentifier("icon_" + condition.getCode(), "drawable", getPackageName());
} else if (getDay().equals("Thu")){
int weatherIconImageResource = getResources().getIdentifier("icon_" + condition.getCode(), "drawable", getPackageName());
} else if (getDay().equals("Fri")){
int weatherIconImageResource = getResources().getIdentifier("icon_" + condition.getCode(), "drawable", getPackageName());
} else if (getDay().equals("Sat")){
int weatherIconImageResource = getResources().getIdentifier("icon_" + condition.getCode(), "drawable", getPackageName());
}
return day;
}
我想將星期幾轉換爲圖像,例如(icon_Mon)。 public String getday
在另一個java類中,不在MainActivity
我想從drawable獲取資源。從Android Studio中的java類獲取資源
我的觀點是如何從另一個java類獲取資源?
有兩種方法:1)將方法中的'Resources'作爲參數傳遞。 2)將方法中的'Context'作爲參數傳遞,並使用該上下文訪問'Resource'。 – Piyush