0

i'm learning how to do simple apps with Android.

i have a strings.xml with several array-strings. what i want is in an Android Activity to select automatically an array-string given an input string that will have the same name as an array-string in strings.xml.

my input is arraylist1, arraylist2 till arraylist20.

the names of my array-strings in my strings.xml are arraylist1, arraylist2 till arraylist20 each Array will have diferent strings.

for example i have an input my-string ="arraylist11". there is a way to refere "my-string" dinamically??

so if input is arraylist11 will get arraylist11 if the input is arraylist7 then get arraylist7 and so on.

how would be the code bellow?? "res.getStringArray(R.array.my-string)"

thanks

1 Answer 1

1

Try using

getResources().getString(getResources().getIdentifier(yourStringName, "string", getPackageName()));

to get your String but this is not recommended.

As per Android Developer

Note: use of this function is discouraged. It is much more efficient to retrieve resources by identifier than by 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.