Android Question List of country names

stanks

Active Member
Licensed User
Longtime User
Hi

How to get a list of country names in current locale?
I don't have any code yet....searching/reading about locate libs/classes

Thanks
 

Mark Read

Well-Known Member
Licensed User
Longtime User
You could load this webpage and parse the html to get a list. Plenty of help on parsing in the forum.
 
Upvote 0

stanks

Active Member
Licensed User
Longtime User
this is not what i wanted....example....your locale is US and you will get list of country names on english. when users device locale is french he will get list of country names ni french, etc. this is what i want. how?

thanks
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
This code does it:
B4X:
Sub Process_Globals
    Public ISOCountryCodes As List
    Public Country As List
End Sub

Sub Activity_Create(FirstTime As Boolean)
    ISOCountryCodes.Initialize
    Country.Initialize
    GetCountryNames
End Sub

Sub GetCountryNames
   Dim jo As JavaObject
   Dim ISOCodes() As String

   jo.InitializeStatic("java.util.Locale")
   ISOCodes = jo.RunMethod("getISOCountries", Null)
   ISOCountryCodes.AddAll(ISOCodes)

'   Dim jo2 As JavaObject
'   jo2.InitializeNewInstance("java.util.Locale", Array As Object("en", "US"))
'   jo.RunMethod("setDefault", Array As Object(jo2))

   Country.Clear
   For i = 0 To ISOCountryCodes.Size - 1
     Dim jo1 As JavaObject
     jo1.InitializeNewInstance("java.util.Locale", Array As Object("en", ISOCountryCodes.Get(i)))
     Dim str0, str(2) As String
     str0 = jo1.RunMethod("getDisplayName", Null)
     str = Regex.Split("[(]", str0)
     Country.Add(str(1).Replace(")", ""))
   Next
End Sub

The commented lines allow to change the language by changing the country code.

Attached a small test program.
 

Attachments

  • CountryNames.zip
    6.3 KB · Views: 217
Upvote 0

stanks

Active Member
Licensed User
Longtime User
Thank you klaus...i've seen simple java code on the net but my java knowledge is not good
 
Upvote 0
Top