How to open a dialog from a text entry on the preference screen?

In my Android application, I want to show a dialog box if the user selects something similar to plain text in PreferenceScreen. I saw How to open AlertDialog from the settings screen? , but this solution is launched from CheckBoxPreference.

In my case, I would like to run from what looks like a TextView (or, I suppose, it could be a button), and then this will lead to the "O" dialog that I already have. Any suggestions on how to do this? Thanks.

+7
source share
1 answer

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; } }); 
+16
source

All Articles