Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A boolean value defined in XML. How to reference in Java?

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.

like image 817
Jaison Brooks Avatar asked Apr 19 '13 21:04

Jaison Brooks


People also ask

Is boolean pass by reference Java?

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.

How are boolean values stored in Java?

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.

How do you define a boolean in Java?

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?


2 Answers

 Resources res = getResources();  boolean enableQAurl = res.getBoolean(R.bool.enableQAurl); 

Source:
http://developer.android.com/guide/topics/resources/more-resources.html

like image 192
kaderud Avatar answered Oct 12 '22 23:10

kaderud


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); 
like image 38
Abish R Avatar answered Oct 12 '22 23:10

Abish R