2017-06-29 165 views
-2

我是Java Android新手。从国家代码获取国家/地区名称字符串int

我想在Locale得到使用国家代码的国家名称(字符串)(参考ISO 3166-1 numeric

试图做类似的东西(其中[...]。getCountry()的返回INT 826 ):

Locale countryName = new Locale("", String.valueOf(profile.getPersonnalInformation().getAddress().getCountry())); 

并使用此得到国家的名字:countryName.getDisplayCountry()

应该正常返回我“英国”但不幸的是我有826

我该怎么做?

在提前感谢你的帮助,

+0

HTTPS ://stackoverflow.com/questions/14275868/get-country-name-from-country-code –

+0

@MehdiKhademloo谢谢你,但我尝试用int数做,而不是像你的例子中的字符串。我已经尝试在String中投射我的int并使用它,但它不起作用,所以你的链接不能帮助我。在您发布之前,我已经阅读过它。 –

回答

2

现在的国家代码(ISO 3166-1alpha-2/alpha-3/numeric)列表的实现。

实施例:

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

+0

谢谢你的魅力。 –

+0

很高兴它适合你。 –

相关问题