I want to add some message in a ListPreference dialog, so I thought about using the attribute android:dialogMessage.
However, when I set this attribute, the list entries (set with android:entries and android:entryValues) are not shown anymore in the dialog (It seems to be a known bug as I could read about it elsewhere).
So it seems that I may need to make a special custom ListPreference in order to show both the dialogMessage and the list entries.
I consider creating a custom class MyListPreference that would be slightly modified for this purpose. I would override onCreateDialogView() to make the changes. However I'm a bit unsure about the cleanest changes to make as I can see two alternatives:
Alternative 1- Create a custom XML layout I would copy the default xml layout for the ListPreference dialog and add a textView. In onCreateDialogView() I would inflate this custom layout.
Alternative 2- Modify the View on the fly In onCreateDialogView() I would call super.onCreateDialogView() and dynamically add a textView to the view it returns.
Question: What do you recommend doing? If alternative 1 is the best, where can I find the default XML layout for the ListPreference dialog so that I can customize it?
Thank you for your help
I would try alternative #2 first. I'm just now developing a huge settings screen with about 50 settings and found out, that modifying the View in onCreateView() of a Preference is quite simple.
@Override
protected View onCreateView(ViewGroup parent) {
View v = super.onCreateView(parent);
((TextView) v).setText(this.text);
return v;
}
I bet it's the same with the Dialog of a ListPreference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With