In my app, I have a Spinner being filled from an enum:
ArrayAdapter<myEnum> enumAdapter = new ArrayAdapter<Stroke> (parentActivity.getApplicationContext(), R.layout.simple_spinner_item, myEnum.values());
enumAdapter.setDropDownViewResource(R.layout.simple_spinner_dropdown_item);
enumSpinner.setAdapter(strokeAdapter);
This uses an override of the enum's toString()
method to get a friendly name for the enum values to display in the Spinner
. Currently my enum has strings hardcoded for the friendly names but I'd like to move these to strings.xml
to support localization.
However, toString doesn't have access to a Context
so I'm not sure how to resolve the resource ids.
Is there any way of getting localised strings in the toString() method of an enum?