Unable To Use Shared Preference Within A Class That Extends View
I am getting an error , when I try to access the shared preference from within class that extends View. The Error : 'The method getSharedPreferences(String, int) is undefined for t
Solution 1:
getSharedPreferences() is a method of a Context
object. So you can try:
public class ViewforRed extends View
{
public final String PREFS_NAME = "GRAPHICS";
SharedPreferences settings;
public ViewforRed(Context context)
{
settings = context.getSharedPreferences(PREFS_NAME, 0);
super(context);
}
Post a Comment for "Unable To Use Shared Preference Within A Class That Extends View"