This is in an Android app, but the question might apply to Java/OOP in general as well.
In my app I have a class Job, which represents a job for the user to complete. One of its properties is status
, which can only have three values: 'to be done', 'pending', or 'completed'.
I want to allow for translation of the app into other languages, so I have been storing these values using Android's string-array
resource type in XML:
<string-array name="jobs_statuses">
<item>To be done</item>
<item>Pending</item>
<item>Completed</item>
</string-array>
I want to be able to make comparisons using the status
property in my code, for instance:
if (myJob.getStatus() == Job.STATUS_COMPLETED) // Do something
I thought about storing the property in the class as an int or other numerical type, and declaring three constants in the class like so:
public static final int STATUS_TO_BE_DONE = 1;
public static final int STATUS_PENDING = 2;
This would allow for easily determining the status of a given job in my code, however, how do I then get a string value back for use in my UI? I've considered having a separate getStatusString
method which might be used like so:
myJob.getStatus(); // returns 1
myJob.getStatusString(); // returns localised string for 'To be done' status
So, in short, I want to be able to:
- Make comparisons using this property
- Get a string value for this property, which is localised based on the user's device language (localised strings stored in XML)
Am I missing an obvious solution?
Thanks in advance.