{"id":104,"date":"2014-12-26T17:51:34","date_gmt":"2014-12-26T16:51:34","guid":{"rendered":"https:\/\/mokrzycki.eu\/blog\/?p=104"},"modified":"2018-12-04T15:46:54","modified_gmt":"2018-12-04T14:46:54","slug":"clearing-items-in-multiselectlistpreference-solution","status":"publish","type":"post","link":"https:\/\/mokrzycki.eu\/blog\/2014\/12\/26\/clearing-items-in-multiselectlistpreference-solution\/","title":{"rendered":"Clearing items in MultiSelectListPreference &#8211; solution"},"content":{"rendered":"<p>Hi, today I was working on MultiSelectListPreference in PreferenceFragment screen. I was going to have multi select list where user would be able select items. Each selected item would be describing specific shortcut from my app to OP desktop.<br \/>\nAfter about half an hour I found out how to restore MultiSelectListPreference with all default items.<\/p>\n<p><!--more--><\/p>\n<p>All you need is to call [java].setValues(new HashSet&lt;String&gt;());[\/java]<\/p>\n<p>For example, in PreferenceFragment, in method onStart(), you are registering preference listener by [java].registerOnSharedPreferenceChangeListener(this)[\/java]<br \/>\nThen when your MultiSelectListPreference changes (it must have a key!), the key will be catched by PreferenceChangeListener. All you need is to call this:<\/p>\n<p>[java]MultiSelectListPreference multiSelectListPreference = (MultiSelectListPreference) findPreference(getString(R.string.sp_shortcuts));<br \/>\nmultiSelectListPreference.setValues(new HashSet&lt;String&gt;());[\/java]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi, today I was working on MultiSelectListPreference in PreferenceFragment screen. I was going to have&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[500],"tags":[5,58,59,52,56,57,60,18],"_links":{"self":[{"href":"https:\/\/mokrzycki.eu\/blog\/wp-json\/wp\/v2\/posts\/104"}],"collection":[{"href":"https:\/\/mokrzycki.eu\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mokrzycki.eu\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mokrzycki.eu\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mokrzycki.eu\/blog\/wp-json\/wp\/v2\/comments?post=104"}],"version-history":[{"count":2,"href":"https:\/\/mokrzycki.eu\/blog\/wp-json\/wp\/v2\/posts\/104\/revisions"}],"predecessor-version":[{"id":106,"href":"https:\/\/mokrzycki.eu\/blog\/wp-json\/wp\/v2\/posts\/104\/revisions\/106"}],"wp:attachment":[{"href":"https:\/\/mokrzycki.eu\/blog\/wp-json\/wp\/v2\/media?parent=104"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mokrzycki.eu\/blog\/wp-json\/wp\/v2\/categories?post=104"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mokrzycki.eu\/blog\/wp-json\/wp\/v2\/tags?post=104"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}