Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/206.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
由于区域设置的原因,android货币代码不正确_Android_Locale_Currency - Fatal编程技术网

由于区域设置的原因,android货币代码不正确

由于区域设置的原因,android货币代码不正确,android,locale,currency,Android,Locale,Currency,我的应用在spinner中有一个语言更改选项,使用的语言如下 1.英语 2.意大利 3.简体中文 4.繁体中文 我已将所有语言字符串加载到相应的values文件夹中。但是,当我尝试加载繁体中文时,我只能获取简体中文文本 在谷歌上搜索了这一点后,我尝试根据语言环境加载语言 以下是我的微调器选择和操作代码 langSpinner = (Spinner)this.findViewById(R.id.lanuage_spinner1); langSpinner.setOn

我的应用在spinner中有一个语言更改选项,使用的语言如下 1.英语 2.意大利 3.简体中文 4.繁体中文

我已将所有语言字符串加载到相应的values文件夹中。但是,当我尝试加载繁体中文时,我只能获取简体中文文本

在谷歌上搜索了这一点后,我尝试根据语言环境加载语言

以下是我的微调器选择和操作代码

        langSpinner = (Spinner)this.findViewById(R.id.lanuage_spinner1);
        langSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() 
        {
            @Override
            public void onItemSelected(AdapterView<?> arg0, View arg1, int pos, long arg3) 
            {   
                if (pos == 0) 
                {
                    langSelected ="en";
                    locale = Locale.ENGLISH;
                }
                else if (pos == 1) 
                {
                    langSelected ="it";
                    locale = Locale.ITALIAN;
                } 
                else if (pos == 2) 
                {
                    langSelected ="zh";
                    locale = Locale.SIMPLIFIED_CHINESE;
                }               
                else if (pos == 3)
                {
                    langSelected ="zh-rTW";
                    locale = Locale.TRADITIONAL_CHINESE;
                }

                changeLang(langSelected, pos);
            }

            @Override
            public void onNothingSelected(AdapterView<?> arg0) {
                // TODO Auto-generated method stub
            }   
        });


public void changeLang(String lang, int pos)
    {
        if (lang.length() != 0)
        {
            //locale = new Locale(lang);            
            android.content.res.Configuration config = new android.content.res.Configuration();
            config.locale = locale;
            Locale.setDefault(locale);
            getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());


       // here using intent call the same activity again

        }
    }
在添加上述用于加载繁体中文字符串的区域设置后,我没有得到“$”值

为什么会发生这种情况


我已经讲过了,由于语言环境的原因,一些货币的使用会出现如上所述的情况。如何克服这个问题。

通过使用以下方法,我能够获得货币代码

String currencyCode = "USD";
Currency currency = Currency.getInstance(currencyCode);
NumberFormat format = NumberFormat.getCurrencyInstance();
format.setMaximumFractionDigits(digits);        
String symbol = currency.getSymbol(Locale.US);

DecimalFormatSymbols decimalFormatSymbols = ((java.text.DecimalFormat) format).getDecimalFormatSymbols();
decimalFormatSymbols.setCurrencySymbol(symbol);
((java.text.DecimalFormat) format).setDecimalFormatSymbols(decimalFormatSymbols);

return format.format(value);
If selected language is English, currency will be as USD
If selected language is Italy, currency will be as USD
If selected language is Simplified Chinese, currency will be as US$
If selected language is Traditional Chinese, currency will be as $
String currencyCode = "USD";
Currency currency = Currency.getInstance(currencyCode);
NumberFormat format = NumberFormat.getCurrencyInstance();
format.setMaximumFractionDigits(digits);        
String symbol = currency.getSymbol(Locale.US);

DecimalFormatSymbols decimalFormatSymbols = ((java.text.DecimalFormat) format).getDecimalFormatSymbols();
decimalFormatSymbols.setCurrencySymbol(symbol);
((java.text.DecimalFormat) format).setDecimalFormatSymbols(decimalFormatSymbols);

return format.format(value);