I have an array like this that defines the entry values for a ListPreference:
<string-array name="sortSelectionEntryValues">
<item>0</item>
<item>1</item>
</string-array>
Now instead of using 0 and 1 in XML, I want to use Java constants like e.g. ORDER_ASC and ORDER_DESC, because later I will access the value of the selected ListPreference entry programmatically and I have to check the value in code, but comparing the value to a well named constant makes code easier to read.
So what I want is something like that:
In Java:
class MyOrderClass
{
public static final String ORDER_ASC="0";
public static final String ORDER_DESC="1";
}
In the XML:
<string-array name="sortSelectionEntryValues">
<item>MyOrderClass.ORDER_ASC</item>
<item>MyOrderClass.ORDER_DESC</item>
</string-array>
Is that somehow possible? Thanks for any hint!
(Please note, the ordering is just a dumb example, I just need to know how to integrate Java constants into the XML definition of an array)
That’s not possible. That said, you will never have to compare “0” to anything. You will likely use
if(MyOrderClass.ORDER_ASC.equals(<selected item from list>){..}so it shouldn’t be an issue.