Note I'm referencing to some comments in the description of my problem but the comments are outside the code container, you have to scroll right to see the comments.
So, I'm trying to get a drawable (image) from R.drawable but has bumped into some issues. I started with attempt 1 (check code comment) and got an image with all bounds=0. But then i read here that getDrawable() might return a false scaling of the image so i followed the notice and tried attempt 2 (check code comment again) but in this case the drawable was null.
Here's the code:
private void setCurrentImage(){
TextView text = (TextView)profileView.findViewById(R.id.profile_image);
//mImage = "flower";
int id = R.drawable.flower;
if(mImage.equals("flower"))
id = R.drawable.flower;
if(mImage.equals("event_splash"))
id = R.drawable.event_splash;
if(mImage.equals("football"))
id = R.drawable.football;
if(mImage.equals("foxhead"))
id = R.drawable.foxhead;
if(mImage.equals("computer"))
id = R.drawable.computer;
//Drawable image = getResources().getDrawable(R.drawable.foxhead); //attempt 1
TypedArray attr = getActivity().obtainStyledAttributes(new int[]{id}); //attempt 2
Drawable image = attr.getDrawable(0); //attempt 2
Log.d("bounds", image.getBounds().toString());
text.setCompoundDrawables(image, null, null, null);
}
As you can see on the commented line mImage = "flower" I tried with 100% certainty the mImage was a valid, still didn't work.