Question

I'm using SharedPreferences to store the choice between 2 checkboxes. It works but now I want that if the value is = 0 must be started my method, if it is equal to 1 is to be launched another method. I created a simple "if" but the method is not launched. Do you have any idea how to do?

sharedPreference = PreferenceManager.getDefaultSharedPreferences(getActivity());
    Integer value = sharedPreference.getInt(SELECTED_ITEM, -1);
             Log.d("va", "value: "+value);
             if (value.equals(0)){


             }else{

             }
Was it helpful?

Solution

Try this

int value = sharedPreference.getInt(SELECTED_ITEM, -1);
         Log.d("va", "value: "+value);
         if (value == 0){


         }else{

         }

A cleaner example

int value = sharedPreference.getInt(SELECTED_ITEM, -1);
    switch(value){
        case 0:
            break;
        case 1:
            break;
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top