问题描述
我有一个问题让一国货币code。我的任务是获取用户的位置,发现他是哪个国家,现在和得到这个国家的货币code。这里的code表示取国名和国家code从所获取的位置:
I have a problem getting a country's currency code. My task is to get the user's location, find out what country he is right now and get this country's currency code. Here's the code that fetches the country name and country code from the acquired location:
Geocoder gc = new Geocoder(this);
List<Address> addresses = gc.getFromLocation(
location.getLatitude(), location.getLongitude(), 5);
textView1.setText(addresses.get(0).getCountryName());
textView2.setText(addresses.get(0).getCountryCode());
这工作完全正常。现在,我应该使用 java.util.Currency中
类来获得一个货币
对象。我可以使用 Currency.getInstance(区域设置区域)
方法。但是,有一个在区域设置
类没有构造函数,只允许该国code被作为参数传递。意味着我不能创建一个为国家语言环境
对象。这又如何解决呢?提前致谢。
This works perfectly fine. Now I should use the java.util.Currency
class to get a Currency
object. I can use the Currency.getInstance(Locale locale)
method. But there's no constructor in the Locale
class that allows only the country code to be passed as an argument. Means I am not able to create a Locale
object for the country. How can this be solved? Thanks in advance.
推荐答案
您应该可以使用 Currency.getInstance(新的语言环境(,code))
,有可能的例外,如果该国code是无效的。
You should be able to use Currency.getInstance(new Locale("",code))
, with a possible Exception if the country code isn't valid.
这篇关于获取一国货币code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!