Why custom DialogPreference doesnt trigger on onSharedPreferenceChanged listener?

杀马特。学长 韩版系。学妹 提交于 2019-12-04 10:53:01

onSharedPreferenceChanged is called because of the inbuilt callback registered on the sharedpreference, so unless you change the key associated with dialogPreference you are not going to get the onSharedPreferenceChanged callback.

So what you could do is everytime dialog is closed, you could change the value in key. Something like below

text = getPersistedString("1")
if(text.length() > 10)
   text = "1";
persistString(text+"1");

Make sure your dialogPreference has a key and android:persistent as true in xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!