Football Fans: Download the 2012 Schedule App from Google Play!


Go Back   Android Forums > Android Development > Application Development

Application Development Dev Lounge for the Coder Folks



Reply
 
LinkBack Thread Tools
Old January 1st, 2011, 03:47 PM   #1 (permalink)
New Member
 
Join Date: Sep 2009
Posts: 6
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to force app to use US Locale?

I do a bunch of numerical calculations in my app, and it force-closes when the user has chosen a locale (e.g. French) where a comma is used instead of a dot for the decimal separator. To resolve this, I could either try to make my app Locale-aware (which seems like a daunting task) or else have the app ignore the user's locale and always use US locale for its internal work. How do I do the latter?

thanks
S

midtoad is offline  
Reply With Quote
Sponsors
Old January 1st, 2011, 04:34 PM   #2 (permalink)
Member
 
Sam Voss's Avatar
 
Join Date: Jun 2010
Location: Wisconsin
Posts: 365
 
Device(s): Droid X2
Thanks: 6
Thanked 44 Times in 43 Posts
Send a message via Skype™ to Sam Voss sam.voss@gmail.com
Default

Make sure the application only allows it to turn an input into a number if it is a number

Ex: no , !# etc, do this by clicking on (in xml) the edittext, then input type, then select the three that apply to numbers, I forget off hand which they are, but you'll recognize them when u see them. This allows a user to only type numbers, period (decimal point), or a - as a negitive sign at the beginning, and that will solve your problem
Sam Voss is offline  
Reply With Quote
Old January 1st, 2011, 06:24 PM   #3 (permalink)
New Member
 
Join Date: Sep 2009
Posts: 6
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default thanks, but

Thanks for that suggestion, and it would be helpful if my users actually were entering numbers. Instead, they are only picking entries in a list, from which calculations are then made and displayed. The problem is that if they select, say 162.5 from a list, and this number is then multiplied internally by, say 2, an exception will result if the French locale is being used because 162.5 is not a correct number format in that locale. Hence I want my app to override the French locale and use US locale instead.
midtoad is offline  
Reply With Quote
Old January 1st, 2011, 06:29 PM   #4 (permalink)
Member
 
Sam Voss's Avatar
 
Join Date: Jun 2010
Location: Wisconsin
Posts: 365
 
Device(s): Droid X2
Thanks: 6
Thanked 44 Times in 43 Posts
Send a message via Skype™ to Sam Voss sam.voss@gmail.com
Default

I'm thinking you could do something along the lines of get the number as 231,24 (, as .) Then getStringValueOf(), then search the string from string.charAt(0) to string.charAt(string.length) or along those lines, posting from my phone. When getting charAt(pos), check if its a , and if it is, change.it to a . , then do ur equasions, then do the same thing, but backwards. Check for a . And replace it with a ,
Sam Voss is offline  
Reply With Quote
Old January 1st, 2011, 07:16 PM   #5 (permalink)
New Member
 
Join Date: Sep 2009
Posts: 6
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default got it

I found the answer I was looking for. to each activity, add code to explicitly set the locale to "en_US". See this page for more info.
midtoad is offline  
Reply With Quote
Reply

Bookmarks

Tags
locale, locale settings


Go Back   Android Forums > Android Development > Application Development User CP
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Locale is $10??! Dabrador Android Applications 65 July 8th, 2010 07:34 PM
Locale and BT? n0m0n Incredible - Support and Troubleshooting 1 June 25th, 2010 03:30 PM
Locale on DI thrillerbee HTC Droid Incredible 10 May 6th, 2010 05:24 PM
Set Locale to UK leedavies HTC Hero 2 December 2nd, 2009 03:03 AM
How do I use Locale? lordfeyr Motorola Droid 0 November 10th, 2009 11:20 PM



All times are GMT -5. The time now is 11:37 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Custom vBulletin Skins by: Relivo