I have a model and it has a specific country flag:
public int getCountryFlag() {
return countryFlag;
}
public void setCountryFlag(int countryFlag) {
this.countryFlag = countryFlag;
}
I am getting Data from an API. The API has a value country code and this could be like: "country":"de","created_at":"2018-08-08 09:17:43","updated_at":"2018-08-08 09:17:43"
I have the flags named as the country code:
de
se
us
....
How can I get the exact resourceID of the image to relate it to the model? I am using RecyclerView.
I tried something like:
int resID = getResources().getIdentifier(object.getString("country"), "drawable", getPackageName());
model.setCountryFlag(R.drawable.sy);
Though that didn't work!