Android: is there a way to remove a string from general settings by its value, and not by key?

Pretty much what the title says.

I have a checkbox which, when checking, places the string in general privileges, and when unchecked should delete the same string.

I wanted to use editor.remove, but it asks for a key, not a string value, and I cannot understand it ... id will be: "recept" + (fav_popis.getInt("brojanje", 0) + 1) but it doesn’t works between the lines that are later used to create a list!

 editor.putInt("brojanje", fav_popis.getInt("brojanje", 0) + 1); editor.putString("recept" + (fav_popis.getInt("brojanje", 0) + 1), s_product); 

any help appreciated.

Thanks!

+4
source share
1 answer

Customize your text as the keys of your shared preference file.

  SharedPreferences prefs = context.getSharedPreferences(name, mode); SharedPreferences.Editor editor = prefs.edit(); String key = checkbox.getText(); if(checkbox.isChecked()) { editor.putString(key, null); } else { editor.remove(key); } editor.commit(); // if you want to get all the list of checkboxes checked to show in listview Set<String> keys = prefs.getAll().keySet(); for(String key : keys) { Log.d(TAG, key); } 
+7
source

Source: https://habr.com/ru/post/1435489/


All Articles