I\'m working on an app that wants to display lengths either in centimeters (cm) or in inches(\"). Is there a way to select the right unit from the locale? In any event I\'m also
Making a small improvement in the solution from @vidstige
I would use getCountry().toUpperCase() to be safe and change the checks to a switch for a cleaner code. Something like this:
public static UnitLocale getFrom(Locale locale) {
String countryCode = locale.getCountry().toUpperCase();
switch (countryCode) {
case "US":
case "LR":
case "MM":
return Imperial;
default:
return Metric;
}
}
Another solution could be creating resources folders for each country like: [values_US] [values_LR] [values_MM] with a boolean resource changed to true. Then read that boolean resource from the code.