If you use this code:
SharedPreferences sharedPrefCheckBox = PreferenceManager
.getDefaultSharedPreferences(this);
inside an adapter class, this
means the adapter class instance, not a class that inherits from Context
.
You need to change that to use your activity, e.g. by passing a reference to the activity to your adapter class (context is usually passed in the adapter constructor). You can then create a variable on the class for the context. In the constructor, set the context passed as parameter to this variable. Use this variable when getting shared preferences.
Note: some adapter classes have getContext()
method that you can use.