https://kotlinlang.org logo
Title
a

Ananiya

07/24/2020, 8:42 AM
Hello 👋, I was trying to save every title here is my code . . . val title = edittext?.text OnClick . . . context.getSharedPreferences(TAG, Context.MODE_PRIVATE).let { It.edit().putStringSet(TAG, HashSet<String>().also{ It.add(title) }).apply() } . . . . . . It saves the title but it also replace the the old with newer(delete all values and add new values) for e.g my first title was foo When I add another title in edittext and save it Like "hello world" during retrieving it shows only [hello world] all I want was [foo, hello world]
g

Gonçalo Palaio

07/24/2020, 8:55 AM
you probably need to get the current values first, add the new one to the set and then call edit().putStringSet(..)
a

Ananiya

07/24/2020, 9:03 AM
Sorry I forget the TAG. I have added in my project but I forget here @Gonçalo Palaio maybe see the edited one. I don't think 🤔 now the key was problem
g

Gonçalo Palaio

07/24/2020, 9:08 AM
in a simplified way you’re doing: putStringSet(TAG, [title]) I think what you want is: currentSet = getStringSet(TAG) currentSet.add(title) putStringSet(TAG, currentSet)
☝️ 1
a

Ananiya

07/26/2020, 11:38 AM
Sorry for delay i was offline, Thanks it work
👍 1