get resource from a fragment
android, imagebutton
Solution
I got this working in a fragment:
int imageresource = getResources().getIdentifier("@drawable/your_image", "drawable", getActivity().getPackageName());
image.setImageResource(imageresource);
Problem
I'm trying to change the source of an ImageButton in android within a fragment. I want to use the method Image.setImageResource() , however i can't use getResources() within the fragment. is there a way round this? getActivity().getResources() does not return any results unfortuantely. I've tried writing a string such as "R.drawable." + {different image names} but i cannot convert that string to an int. How else could this be done? I just want to change some imageButtons with source files dependent on different things.