3

) i'm a C# developer and now i started to program apps for android. In C# we have the CultureInfo object where we can set the values for the culture of the aplication. There is a similar object in java (android) to let me do that ¿? i found that i can set the locale with this Locale.setDefault(Locale.FRENCH); but how i set the date, number adn monetaris symbols ¿?

Here is the code in C# that i use:

CultureInfo objCultureInfo = new CultureInfo("en-US", true);
objCultureInfo.NumberFormat.NumberDecimalDigits = 2;
objCultureInfo.NumberFormat.NumberDecimalSeparator = ".";
objCultureInfo.NumberFormat.NumberGroupSeparator = ",";
objCultureInfo.DateTimeFormat.DateSeparator = "/";
objCultureInfo.DateTimeFormat.TimeSeparator = ":";
objCultureInfo.DateTimeFormat.FullDateTimePattern = "MM/dd/yyyy HH:mm:ss";
objCultureInfo.DateTimeFormat.ShortDatePattern = "MM/dd/yyyy";
objCultureInfo.DateTimeFormat.ShortTimePattern = "HH:mm:ss";
objCultureInfo.NumberFormat.CurrencySymbol = "$";
Cultura.CulturaAplicacion = objCultureInfo;

Thanks!

Ramiro Nava Castro
  • 337
  • 1
  • 7
  • 14

2 Answers2

2

In my opinion you shouldn't change the Locale value at all. The user sets this value device wide in the settings. You can also set your date and time format there, too. You should use those values in your app instead of overriding them with custom ones, because the user knows better, which language and formats he/she wants to use.

henrik
  • 708
  • 7
  • 14
  • Ok but if i want to know waht type of number decimal separator is set by the user in his mobile device or in which format he sees the date ¿? i ask this because i must save the floats, long numbers in a specific way and the dates too, so must format and transform the values before saving. – Ramiro Nava Castro Jan 29 '12 at 21:08
  • I'm with Henrik on this, if your app goes multilingual, expect major problems. If there are specific formats you need to use, settle on your own predetermined language settings and let the user locale as set by the user handle all the display formatting. If no locale supports your preferred settings for local storage, format them manually or create your own formatter rather than changing an existing locale. – Timothy Groote Jan 31 '12 at 11:13
0

I think I found what I needed here:

http://developer.android.com/reference/java/text/NumberFormat.html

Thanks!

Ramiro Nava Castro
  • 337
  • 1
  • 7
  • 14