11

In my Android app I want to show a Dialog if the user selects on something that looks like plain text in a PreferenceScreen. I have seen How to open AlertDialog from preference screen?, but that solution launches from a CheckBoxPreference.

In my case, I'd like to launch from something that looks like a TextView (or I suppose it could be a button), and it would then lead to an "About" dialog I already have. Any suggestions how to do that? Thanks.

Community
  • 1
  • 1
gcl1
  • 4,070
  • 11
  • 38
  • 55

1 Answers1

20

preferences.xml file:

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
    <Preference android:key="dialog_preference" />
</PreferenceScreen>

Activity:

addPreferencesFromResource(R.xml.preferences);

dialogPreference = (Preference) getPreferenceScreen().findPreference("dialog_preference");
dialogPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
        public boolean onPreferenceClick(Preference preference) {
            // dialog code here
            return true;
        }
    });
myki
  • 773
  • 5
  • 7
  • Thanks for your reply, myki. What would the xml type be for this specific preference? Currently, I only have CheckBoxPreferences and EditTextPreferences. – gcl1 May 15 '12 at 22:56