Can I use Android Integer resources in switch statements?

I have a file "numeric.xml" in my "values" directory, which contains most of the project integer constants. I would like to use some of these constants in the switch statement, but Eclipse / Java does not like this because it does not consider "resources.getInteger (R.integer.INTEGER_NAME)" as constant. Is there a way to make the compiler and / or Eclipse see that it is a constant, or do I just need to live with if / else goals?

Edit: I tried to execute "final int INTEGER_NAME = resources.getInteger (R.integer.INTEGER_NAME)" and using INTEGER_NAME in the case argument, but that didn't work either.

+3
source share
3 answers

, . ? . (, values-land .) xml.

, . , , - Runnable ( Callable), , , .

+3

, resources.getInteger(R.integer.INTEGER_NAME) , resources.getString(R.string.STRING_NAME): , case. if/else.

+2

I tried these and worked

Resources r = getResources(); 
int i = r.getInteger(R.integer.lol); 
switch (i) { 
    case 1: 
        Log.d("lol", "hehehe0"); 
        break; 
    default: 
        break; 
}
0
source

All Articles