I am trying to set my image in my ImageView through a variable (item is the variable name, which I will be setting to lowerCase). However, it is not working and resID will return 0.
Here is my code:
ImageView iv = (ImageView)v.findViewById(R.id.imgView);
if (item != null) {
Log.i("item: ", item.toLowerCase());
int resID = getResources().getIdentifier(item.toLowerCase(), "drawable", "package.name");
Log.i("resid: ", String.valueOf(resID)); //will return 0 - im guessing this is where the problem is
iv.setImageResource(resID);
}
I used this as a guide Android, reference things in R.drawable. using variables? but none of the other solutions work for me, in fact they all gave me the same result (returning 0). I can provide more code if needed (just didn't want it to be bombastic). Thanks in advance!