I'm trying to write some code that will reference a bool.xml file and will reference the current value inside the bool.
<bool name="enableQAurl">true</bool>
With this I want to be able to reference this in code, so that if it's set to True it does something and if false does something else. Just a simple If and else statement.
Any code references or feedback is greatly appreciated.
Java only has "pass by value", not "pass by reference." However, there are other techniquest to achieve the same effect. The most obvious is to return a boolean.
Boolean values in Java always take more than one byte, but how much more depends where the value is being stored – in the stack, or on the heap. The JVM uses a 32-bit stack cell, which will cause each boolean value to occupy the complete stack cell of 32 bits.
Answer: Boolean is a primitive data type that takes either “true” or “false” values. So anything that returns the value “true' or “false” can be considered as a boolean example. Checking some conditions such as “a==b” or “a<b” or “a>b” can be considered as boolean examples. Q #3) Is boolean a keyword in Java?
Resources res = getResources(); boolean enableQAurl = res.getBoolean(R.bool.enableQAurl);
Source:
http://developer.android.com/guide/topics/resources/more-resources.html
The above answer of kaderud's will work perfectly. If you are not in Activity, you have to use your context.
If you are in fragment or adapter then you have to follow below.
boolean enableQAurl = context.getResources().getBoolean(R.bool.enableQAurl);
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