Domanda

So I am trying to make an application where some data is interpreted depending on which country the user lives in, such as currency and cost of living, etc. So I was wondering is there an API that I can use which lists all the countries, or do I have to create a spinner and list every country by hand (Which is too much work).

And do you guys suggest using spinners and have a dropdown list,or use the permission for wifi and then just locate the country?

Thanks in advance!

È stato utile?

Soluzione

    Locale[] locales = Locale.getAvailableLocales();
    ArrayList<String> countries = new ArrayList<String>();
    for (Locale locale : locales) {
        String country = locale.getDisplayCountry();
        if (country.trim().length()>0 && !countries.contains(country)) {
            countries.add(country);
        }
    }
    Collections.sort(countries);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top