How to change currency symbol based on user choice
I want to give my users the possibility to choose in the settings what currency symbol they want to use (e.g. € and $). What is the best way to change the symbols in the app according to the setting? So I am able to read out the setting and know in my actvity what symbol the user wants. my way would be to do always a switch or if statement and for each currency symbol to create own text. I wonder if there is a more elegant way to go to change the currency symbol in all my textviews.
i have stored the symbol in sharedpreferences and I can read it from sharedpreferences in each of my activities. Now I have to create for each textview which contains a curr开发者_StackOverflow社区ency symbol, a if statement?
Is there no possibility to store it somehow in xml and take out the right symbol like it is done with different languages?
Depending on the way you're implementing your UI (using styles etc.) it shouldn't be a big deal switching between € and $. As far as I can see it's not a bad thing tough storing the user preferred symbol as a preference.
Probably the Shared Preferences will be the best approach: http://developer.android.com/reference/android/content/SharedPreferences.html This is a good tutorial and well explained in my opinion of what the Shared Preferences could do: http://mobile.tutsplus.com/tutorials/android/android-application-preferences/
Simple save the symbol in a Shred Preference value, and the retrieve it when you need it.
精彩评论