LA_
LA_

Reputation: 20409

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(){}

Upvotes: 0

Views: 5140

Answers (1)

Sebastian Breit
Sebastian Breit

Reputation: 6159

You must call this using your context;

YourActivity.this.findPreference("pref_key");

that should work ;)

Upvotes: 2

Related Questions