[英]How to call findPreference from the main activity, dialog's onClick function?
I have the following dialog in main activity: 我在主要活动中有以下对话框:
@Override
protected Dialog onCreateDialog(int id) {
final Dialog dialog;
switch(id) {
case DIALOG_NAME:
builderDialog.setMessage(getString(R.string.dialog_text))
.setCancelable(false)
.setPositiveButton(R.string.dialog_share_yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// how should I call findPreference here?
PreferenceScreen screen = (PreferenceScreen) findPreference("pref_key");
...
}
})
I am getting the following error: 我收到以下错误:
The method findPreference(String) is undefined for the type new DialogInterface.OnClickListener(){}
方法findPreference(String)未定义类型new DialogInterface.OnClickListener(){}
You must call this using your context; 你必须使用你的上下文来调用它;
YourActivity.this.findPreference("pref_key");
that should work ;) 应该工作;)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.