1

I am building an Andorid application. I have this String array which contains the values for the image files:

String[] stringArray = new String[]{ "R.drawable.image1", "R.drawable.image2 ", "R.drawable.image3", "R.drawable.image4"};

Is is it possible to convert the stringArray to something like that, if yes h so the Android app can read the resource values properly ? If yes then how ?

int[] intArray = new int[]{R.drawable.image1, R.drawable.image2, R.drawable.image3, R.drawable.image4};
4
  • 3
    but the first one is not a String, Commented Mar 17, 2015 at 15:50
  • 1
    Not only it's possible, but it really should be like that. Because R ids are stored as ints, not as strings. Commented Mar 17, 2015 at 15:50
  • 1
    Your stringArray line shouldn't compile Commented Mar 17, 2015 at 16:05
  • I added the right one Commented Mar 17, 2015 at 16:10

1 Answer 1

1

you can get the identifiers if you know the resource type. Maybe just tokenize the string and get the type, then call one of theese methods answered here: How to get a resource id with a known resource name?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.