Search code examples
javaandroidandroid-preferences

Android programmatically added ListPreference has missing title


In my PreferenceFragment I have a ListPreference that I add programmatically in my PreferenceScreen like this

ListPreference groupPref = new ListPreference(getActivity());
groupPref.setTitle("Aktuelle Gruppe");
groupPref.setKey("groupObjectId");
groupPref.setEntries(entries);
groupPref.setEntryValues(values);

PreferenceScreen screen = this.getPreferenceScreen();
screen.addPreference(groupPref);

This works generally and the Preference has a title in the list of preferences. But it has no title when the choosing dialog opens.

screenshot

How to make it show a title in that dialog?


Solution

  • Call setDialogTitle(). setTitle() sets the title in the row in the PreferenceScreen.