Reputation: 4120
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.
Upvotes: 11
Views: 6212
Reputation: 763
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;
}
});
Upvotes: 20