• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Accessing string resource via getString method

elk0019

Lurker
Hello,

I am making some modifications to a flaq quiz app for android and one of them is to add a bonus question when the button containing the name of the country the flag represents is pressed and also asks the user to guess what is the capital of that same country.

I have the code that loads up the country flag and extrapolates the name of the country from the name of the file that contains the flag image.

I am basically modifying the same code to work with the strings.xml file as I have added all capitals corresponding to each country in there. I just need to get around the fact that I am trying to get those string resources via the getString() method, for example:

capital = name.substring(name.indexOf('-') + 1).replace('_',' ');
correctAnswer = getString(R.string.capital);

Apparently I cannot use this approach to dynamically obtain a capital name by comparing against it's countrie's file name.
 
Back
Top Bottom