Android get all countries on array spinner

As for me, i iterate the available Locales and add each of the item into an arrayList. And of course i have to ignore duplicates, and empty strings. Here is my code:

 SortedSet<String> countries = new TreeSet<>();
 for (Locale locale : Locale.getAvailableLocales()) {
     if (!TextUtils.isEmpty(locale.getDisplayCountry())) {

Spinner citizenship = (Spinner)findViewById(;
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, getCountryListByLocale().toArray(new String[0]));

You can use

private static final String DEFAULT_LOCAL = "Portugal";

Then use it to set default selection as follows.

ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, array_spinner);


enter image description here

Create arrays.xml in res/values

<?xml version="1.0" encoding="utf-8"?>

    <string-array name="country_arrays">
        <item>United States</item>
        <item>New Zealand</item>


Then use following in your activity to get all the countries.

array_spinner = getResources().getStringArray(R.array.country_arrays);

A helpful and customizable Country Picker for your needs.


repositories {
    maven { url "" }

compile 'com.github.ekimual:country-picker-x:1.0.0'

Sample Usage:

/* Declare */
CountryPickerDialog countryPicker;

/* Name of your Custom JSON list */
int resourceId = getResources().getIdentifier("country_avail", "raw", getApplicationContext().getPackageName());

countryPicker = new CountryPickerDialog(MainActivity.this, new  CountryPickerCallbacks() {
      public void onCountrySelected(Country country, int flagResId) {
            /* Get Country Name: country.getCountryName(context); */
            /* Call countryPicker.dismiss(); to prevent memory leaks */

      /* Set to false if you want to disable Dial Code in the results and true if you want to show it 
         Set to zero if you don't have a custom JSON list of countries in your raw file otherwise use 
         resourceId for your customly available countries */
  }, false, 0);;


Leave a Comment