我希望我的應用程序在共享首選項中保存textView2。這是我保存複選框狀態的當前共享首選項代碼(選中/未選中)。如何將共享首選項中的textView保存?
private boolean getFromSP(String key){
SharedPreferences bifrostPrefs = getApplicationContext().getSharedPreferences("bifrostPrefs", android.content.Context.MODE_PRIVATE);
return bifrostPrefs.getBoolean(key, false);
}
private void saveInSp(String key,boolean value){
SharedPreferences bifrostPrefs = getApplicationContext().getSharedPreferences("bifrostPrefs", android.content.Context.MODE_PRIVATE);
SharedPreferences.Editor editor = bifrostPrefs.edit();
editor.putBoolean(key, value);
editor.commit();
}
我從來沒有真正與共享prefrences合作過,所以我真的不知道我將如何創建一個新的共享prefrence救我textview2。
您無法將視圖存儲在共享首選項中。但是你可以保存字符串,所以只需要使用putString而不是putBolean,其他所有的工作都是一樣的。 –