如何获得用户偏好的单位? (公制(米)还是英制(英里))?

发布于 2024-11-29 05:22:18 字数 46 浏览 0 评论 0原文

我想知道英里和米之间的用户首选单位是什么。似乎“Locale”类不允许这样做。

I would like to know what are the user-preferred units between miles and meters. It seems that the "Locale" class doesn't allow that.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

不知所踪 2024-12-06 05:22:18

尽管无法使用 Locale 获取首选单位,但您可以默认假设 Locale 指示美国或缅甸 (locale.getISO3Country().equalsIgnoreCase("usa") || 区域设置。 getISO3Country().equalsIgnoreCase("mmr")) 首选单位为英制,否则首选单位为公制。在单位可以以英制或公制形式显示的任何情况下,显示的测量系统应该是用户可设置的首选项。

某些国家的单位有某些特殊之处。 (另请参阅撰写本文时已接受的答案。)例如,尽管英国首选的日常单位是公制单位,但也有一些例外,特别是

  • 地面交通中的英里和每小时英里;
  • 英里/小时,以风速表示;
  • 品脱和加仑,用于牛奶和啤酒(但不是大多数其他食品和饮料);石头
  • ,或者石头和磅,代表一个人的重量。

Although there isn't a way to get the preferred units using Locale, you can assume by default that if the Locale indicates the United States or Myanmar (locale.getISO3Country().equalsIgnoreCase("usa") || locale.getISO3Country().equalsIgnoreCase("mmr")) the preferred units are imperial, otherwise the preferred units are metric. In any case where units may be shown in either imperial or metric form, the measurement system shown should be a user-settable preference.

There are certain idiosyncrasies involving units in some countries. (See also the accepted answer at the time of this writing.) For example, although the preferred everyday units in the United Kingdom are metric units, there are some exceptions, notably—

  • miles and miles per hour, in ground transportation;
  • miles per hour, in wind speeds;
  • pints and gallons, for milk and beer (but not most other foods and beverages); and
  • stone, or stone and pounds, for a person's weight.
偏闹i 2024-12-06 05:22:18

我认为对于所有语言环境的公制/英制问题不一定有正确的答案。

例如,在英国,我们通常使用英里来表示长途旅行,例如汽车旅行,使用英尺和英寸来表示人的身高,但也可能使用米来描述房间的尺寸。

我们几乎总是使用升来测量液体体积,但啤酒和有时仍然以品脱出售的牛奶除外。

公斤通常比磅和盎司更受欢迎,但大多数食谱书都会列出两者,因为有些人仍然有使用后者的秤。

我认为您必须做一些研究,找出哪些国家/地区使用哪种比例来测量您感兴趣的内容(当然,让用户可以手动选择其中一个或另一个。)

I don't think there's necessarily a correct answer to the Metric/Imperial question for all locales.

For example, in the UK we generally use miles for large distances like a car journey, feet and inches for people's height but may use meters to describe the dimensions of a room.

We almost always use litres for measuring liquid volume except for beer and sometimes milk which can still be sold in pints.

Kilograms are usually preferred to pounds and ounces but most recipe books will list both since some people still have scales which use the latter.

I think you will have to do some research to find out which countries use which scale for what you're interested in measuring (and of course, give the user the option to select one or the other manually.)

猫弦 2024-12-06 05:22:18

由于美国以外的一些人可能已将语言设置为英语(美国),因此最终最好采用 getSimCountryIso() 的返回值,而不是 getISO3Country()

TelephonyManager tm = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String countryCode = tm.getSimCountryIso();

如果countryCodeus SIM 卡是美国的,因此英制单位可能是更好的选择 - 在任何其他情况下都应用公制系统

Since some people outside the US may have set the language to English (US) it is eventually better to take the return value of getSimCountryIso() instead of getISO3Country()

TelephonyManager tm = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String countryCode = tm.getSimCountryIso();

If the countryCode is us the SIM card is an american and therefore imperial units might be the better choice - in any other case the metric system is applied

忆依然 2024-12-06 05:22:18
  1. 构建区域设置:国家/地区:公制

  2. 您可以使用Locale.getDefault()< /code> 为您正在运行的设备的用户获取适当的区域设置

  3. 在构建的表上执行搜索

结果就是你的!

  1. Build a Locale : Country : Metric

  2. You can use Locale.getDefault() to get an appropriate locale for the user of the device you're running on

  3. Perform a search on the built table

Result is yours!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文