从国家代码int获取国家名称字符串 [英] Get country name String from country code int
本文介绍了从国家代码int获取国家名称字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是Java Android新手.
I am new in Java Android.
我想使用区域设置(参考 ISO 3166-1数字)
试图做类似的事情(其中[...].getCountry()返回int 826):
Tried to do something like that (where [...].getCountry() return int 826):
Locale countryName = new Locale("", String.valueOf(profile.getPersonnalInformation().getAddress().getCountry()));
并使用以下代码获取国家/地区名称: countryName.getDisplayCountry()
and get the name of country using this: countryName.getDisplayCountry()
通常应该返回"英国",但不幸的是我有826.
It should normally return me "United Kingdom" but unfortunately I have 826.
我该怎么做?
在此先感谢您的帮助,
推荐答案
现在已实现国家/地区代码( alpha-2 /
Now an implementation of country code (ISO 3166-1 alpha-2/alpha-3/numeric) list as Java enum is available at GitHub under Apache License version 2.0.
示例:
int c_code=profile.getPersonnalInformation().getAddress().getCountry());// 392
CountryCode cc = CountryCode.getByCode(c_code);
String country_name=cc.getName(); // "Japan"
成绩
dependencies {
compile 'com.neovisionaries:nv-i18n:1.20'
}
Github
https://github.com/TakahikoKawasaki/nv-i18n
这篇关于从国家代码int获取国家名称字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文