B4A Library Country Picker

A wrap for this Github Project - Download the complete B4A project from here (the project is too big to upload to the forum). Attached is the B4A library files.

It returns the name, the dialling code, and the ISO code of the selected country

1.gif


Have tested it on Kitkat and Lollipop and it is working on both.

Sample Code:

B4X:
#Region  Project Attributes
    #ApplicationLabel: b4aCountryPicker
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: portrait
    #CanInstallToExternalStorage: False
#End Region

#AdditionalRes: ..\resource
#AdditionalRes: ..\DemoRes
#AdditionalRes: ..\LibRes


'#AdditionalRes: C:\Users\----------2\Documents\Basic 4 Android\JOHAN APPS\JHS LIBS\resource\b4a_appcompat, de.amberhome.objects.appcompat
'#AdditionalRes: C:\ANDRIOD_SDK_TOOLS\extras\android\support\v7\appcompat\res, android.support.v7.appcompat
'#AdditionalRes: C:\ANDRIOD_SDK_TOOLS\extras\google\google-play-services\libproject\google-play-services_lib\res, com.google.android.gms
'#AdditionalRes: C:\ANDRIOD_SDK_TOOLS\extras\android\support\design\res, android.support.design

'#ExcludeClasses: .games, .drive, .ads, .fitness, .wearable, .measurement, .cast, .auth, .nearby
'#ExcludeClasses: .tagmanager, .analytics, .wallet, .plus, .gcm, .maps, .panorama

'#Extends: android.support.v7.app.AppCompatActivity

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private Button1 As Button
    Dim cp As CountryPicker


    Private Label1 As Label

End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:

    Activity.LoadLayout("main")
    cp.Initialize("cp")

End Sub

Sub Activity_Resume


End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Button1_Click


    cp.StartCountryPicker

End Sub

Sub cp_country_selected(country As String, dialingcode As String, isocode As String)

    Log("Selected country = " & country)
    Log("Dialing Code = +" & dialingcode)
    Log("ISO Code = " & isocode)
    Label1.Text = "Selected country = " & country & Chr(10) & "Dialing Code = +" & dialingcode & Chr(10) & "Iso Code = " & isocode

End Sub

Take note of the B4A manifest file.

B4A Library:

CountryPicker
Author:
Github: Mike Lau, Wrapped by: Johan Schoeman
Version: 1
  • CountryPicker
    Events:
    • country_selected (country As String, dialingcode As String, isocode As String)
    Methods:
    • Initialize (paramString As String)
    • IsInitialized As Boolean
    • StartCountryPicker
 

Attachments

  • CountryPickerLibFiles.zip
    13.2 KB · Views: 480
Last edited:

Johan Schoeman

Expert
Licensed User
Longtime User
Seems like won't work with older ver of B4A.
What version of B4A are you using? I have done the wrapper some 15 months ago with whatever B4A version was applicable at that time. Have just tried it with B4A V7.30 on an Android 7.0 device and it is working.
 
Last edited:

Ibrahim Saleh

Member
Licensed User
Longtime User
Im getting error from this library even when I try your sample project

B4X:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
** Activity (login) Create, isFirst = true **
** Activity (login) Resume **
** Activity (login) Pause, UserClosed = true **
** Activity (signup) Create, isFirst = true **
signup_activity_create (java line: 397)
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/mikelau/countrypickerxsample/MainActivity;
    at countrypickerwrapper.countrypickerWrapper.Initialize(countrypickerWrapper.java:78)
    at com.myteware.paygurish.signup._activity_create(signup.java:397)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
    at com.myteware.paygurish.signup.afterFirstLayout(signup.java:105)
    at com.myteware.paygurish.signup.access$000(signup.java:17)
    at com.myteware.paygurish.signup$WaitForLayout.run(signup.java:83)
    at android.os.Handler.handleCallback(Handler.java:938)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:223)
    at android.app.ActivityThread.main(ActivityThread.java:7989)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:635)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: java.lang.ClassNotFoundException: com.mikelau.countrypickerxsample.MainActivity
    ... 14 more
 

Johan Schoeman

Expert
Licensed User
Longtime User
Im getting error from this library even when I try your sample project

B4X:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = true **
** Activity (login) Create, isFirst = true **
** Activity (login) Resume **
** Activity (login) Pause, UserClosed = true **
** Activity (signup) Create, isFirst = true **
signup_activity_create (java line: 397)
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/mikelau/countrypickerxsample/MainActivity;
    at countrypickerwrapper.countrypickerWrapper.Initialize(countrypickerWrapper.java:78)
    at com.myteware.paygurish.signup._activity_create(signup.java:397)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
    at com.myteware.paygurish.signup.afterFirstLayout(signup.java:105)
    at com.myteware.paygurish.signup.access$000(signup.java:17)
    at com.myteware.paygurish.signup$WaitForLayout.run(signup.java:83)
    at android.os.Handler.handleCallback(Handler.java:938)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:223)
    at android.app.ActivityThread.main(ActivityThread.java:7989)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:635)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: java.lang.ClassNotFoundException: com.mikelau.countrypickerxsample.MainActivity
    ... 14 more
Have you downloaded the B4A library files in post #1 of this thread and copied them to your additional library folder?
 

Ibrahim Saleh

Member
Licensed User
Longtime User
Yes Did that..Im using B4A 11.20. And the sample project is not working even. Its giving me the same error
 

Johan Schoeman

Expert
Licensed User
Longtime User
Yes Did that..Im using B4A 11.20. And the sample project is not working even. Its giving me the same error
6 years old. Find something on the forum that will suite your needs.
 
Top