0
我有一個應用程序,其中包含ArrayList中存儲在共享首選項中的項目,我想從共享首選項中刪除ArrayList中的特定項目。如何做到這一點如何從android中的sharedPreference中存儲的arraylist中刪除項目?
代碼: -
String jsonData = sharedPreference.getAppsArrayListData();
Type type = new TypeToken<ArrayList<WhiteListModel>>() {
}.getType();
whiteListStorage = gson.fromJson(jsonData, type);
共享優先級代碼: -
private SharedPreferences pref;
private SharedPreferences.Editor editor;
// Context
private Context _context;
// Shared pref mode
int PRIVATE_MODE = 0;
// Sharedpref file name
private static final String PREF_NAME = "pref";
private static final String NOTIFICATION = "appData";
public MySharedPreference(Context context) {
this._context = context;
pref = _context.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
editor = pref.edit();
}
public void saveAppsArrayListData(String scoreString) {
editor.putString(NOTIFICATION, scoreString);
editor.commit();
}
public String getAppsArrayListData() {
return pref.getString(NOTIFICATION, "");
}
}
只需從arrayList中刪除位置或字符串中的數據,並在sharedPreference中重置該值。 –
請參考一些代碼snipshot – Niraj