Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open a Dialog from a text entry on a PreferenceScreen?

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.

like image 806
gcl1 Avatar asked May 10 '12 15:05

gcl1


1 Answers

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;
        }
    });
like image 172
myki Avatar answered Oct 07 '22 06:10

myki