Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dynamically set currency symbol

In my app there are a lot of textviews which contain a currency symbol.

Now I want the user to set the symbol. I created a sharedpreference and added there all the existing currencies. Unfortunatelly there are approximately 20 different currencies out there.

Therefor I am struggling how to change dynamically the currency symbol in all my textviews. I could create for each a big switch case statement (with 20 cases) but this will blow up my code extremly.

Is there another technique how I can change the symbol. E.g. with help of an xml file like the different languages...

like image 611
tobias Avatar asked Feb 13 '26 09:02

tobias


1 Answers

The efficient way to do this is by using the Locale and Currency classes.

1.Create the Locale object based on the user input

Example:

       Locale locale=new Locale("en", "US");

2.based on this get the currency symbol and display it.

Example:

     Currency currency=Currency.getInstance(locale);
     String symbol = currency.getSymbol(); 
like image 165
Balaji.K Avatar answered Feb 15 '26 00:02

Balaji.K



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!