I've looked and tried many things but it seems my App isn't getting the values for strings in strings.xml. It actually seems like it's passing blank. I think there's an issue initializing.
strings.xml
<string name="itb_cityID">2</string>
<string name="itb_city">New York</string>
constants.java excerpt:
public class ConstantData {
public static String cityID="2";
public static String city="New York";
How do I set cityID = R.strings.itb_cityID
and city=itb_city
the correct way?
String yourString = Context.getResources().getString(R.string.your_string);
Note: You can't use Context
statically. If you're inside an Activity, simply use this
or call getResources()
directly. Otherwise you'll need to obtain a handle to your application's context via getApplicationContext()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With