0
我为我的应用实施了一些应用偏好设置。对于字符串他们工作很好,但不是布尔值。例如。Android应用偏好不起作用
public class MdSharedPrefs {
public final static String PREFS_NAME = "prefs";
public static boolean getSSFlag(Context context) {
SharedPreferences prefs = context.getSharedPreferences(PREFS_NAME, 0);
return prefs.getBoolean(context.getString(R.string.pref_key_ss), false);
}
public static void setSSFlag(Context context, boolean newValue) {
SharedPreferences prefs = context.getSharedPreferences(PREFS_NAME, 0);
Editor prefsEditor = prefs.edit();
prefsEditor.putBoolean(context.getString(R.string.pref_key_ss),
newValue);
prefsEditor.commit();
}
}
而这就需要
<string name="pref_key_ss"></string>
中的strings.xml。当我删除这行时,该项目不会编译。但是当我离开它时,这个布尔值pref不起作用。当我点击它并返回到主屏幕,然后返回到首选项时,该值不会被检查。
不过,对于字符串它工作正常。
任何想法什么是错?
在我的应用
我不知道为什么”你创建静态字符串,我th墨水问题与.. – 2011-12-26 13:18:32