findpreference undefined type

廉价感情. 提交于 2020-01-06 19:43:49

问题


I am trying to set a value to a ListPreference and always get the error message:

The method findPreference(String) is undefined for the type new DialogInterface.OnClickListener(){}

This is my code:

ListPreference lp = (ListPreference) findPreference("enableTranslations");
lp.setValue("");

Thanks


回答1:


You simply call findPreference in wrong place (in OnClickListener).

Call it in method of class that has findPreference method (PreferenceManager or PreferenceActivity) or on object of such type.



来源:https://stackoverflow.com/questions/7569048/findpreference-undefined-type

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