I am implementing my own custom DialogPreference subclass, like so:
public class MyCustomPreference extends DialogPreference
{
private static final String androidns = "http://schemas.android.com/apk/res/android";
private String mDialogMsg;
public MyCustomPreference(Context context, AttributeSet attrs)
{
super(context, attrs);
mDialogMsg = attrs.getAttributeValue(androidns, "dialogMessage");
...
}
...
}
As you can see, I get the dialogMessage XML attribute and save it in the member variable mDialogMsg.
My problem is: my current code does not allow for the dialogMessage XML attribute to be specified as a string resource id in the XML.
In other words, this works:
android:dialogMessage="Hello world!"
But this doesn’t:
android:dialogMessage="@string/hello_world"
If I specify it as a resource id in the XML, the resource id gets saved to mDialogMsg, not the string resource itself. Now, I know I could do:
context.getString(attrs.getAttributeValue(androidns, "dialogMessage"))
But then the user would not be able to enter a normal string in the XML (i.e. a non-resource id). I want to give the user the option of doing both. How do I do this?
1 Answer