I've only ever had to work with Strings within the strings.xml file before, but now I have a case where I need to work with Boolean and Integer items.
<item type="integer" name="usenetPort">563</item>
<item type="bool" name="usenetUseSSL">true</item>
I usually use getResources().getString(R.strings.my_string)
to retrieve a value, but that doesn't work with Boolean and Integers. I tried getInteger()
and getBoolean()
but Eclipse says that's wrong.
How do I get the value from Booleans and Integers?
To convert String to Boolean, use the parseBoolean() method in Java. The parseBoolean() parses the string argument as a boolean. The boolean returned represents the value true if the string argument is not null and is equal, ignoring case, to the string "true".
android:text="@string/hello" /> String string = getString (R. string. hello); You can use either getString(int) or getText(int) to retrieve a string.
Using the Strict Equality Operator (===) In this method, we will use the strict equality operator to compare strings to Boolean. The strict equality always returns false when we compare string and boolean values as it also checks for the data type of both operands.
When the Properties of your file are loaded you can use the Boolean -Class to get the Properties: Boolean. getBoolean("your. property");
It works for me, first I openned Strings.xml and added this:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item type="integer" name="mynumber">4</item>
</resources>
Then in the code I get the value by doing this:
int number= getResources().getInteger(R.integer.mynumber);
You have to use R.integer.* and not R.string.*
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