0

Hello guys I need to refer my items in RES > values > strings.xml and get the value of them. These items are with name: cd_1, 2... What I want? I want to get all items values programmatically using R.string.cd_x where X is the value I want to replace in for loop to get the item value. Is there a way to do this?

Below Is what I'm trying(Where y is a number...could be 8, 9, 10...):

for(int i = 1; i<y; i++){

        title = "cd_"+String.valueOf(i);
        title_id = Resources.getSystem().getIdentifier(title, "string", package_name);
        title= Resources.getSystem().getString(title_id);
        addTitle(new Title(i, title));
    }

1 Answers1

0

You can approach this differently. Use string array resource instead. For example:

<string-array name="system">
    <item>@string/earth</item>
    <item>@string/moon</item>
</string-array>

And the you can just call:

String myArray[] = getResources().getStringArray(R.array.system);
Yunus Kulyyev
  • 1,022
  • 15
  • 26
  • Helo Yunus, I thanks for your attetion, but it doesn't work for me. It's easier if I use this. But I need I have a lot of information for each cd I have. I have a lot of cd, for example: I have (cd_1, Information 1, Information 2, ...) It's easier if I use it in another logic, but now, it doesn't work for me, I need like I posted. But anyway, I really apreciate your help!!! – Fábio Monteiro Jan 07 '20 at 21:47