Provides country codes in accordance with ISO-3166-1 and localized names for each country
- Create a new library project from this repository and reference it in your project
Add the following code to your XML for the preferences. The class CountryPreference extends ListPreference and has the same appearance. It ignores the attributes android:entries, android:entryValues, android:defaultValue and android:summary because it comes with its own implementation for those.
Be sure to set android:key to the preference key that you want to store the country code in. For android:title, provide a value from your string resources, for example, which will be used as the preference's caption.
<im.delight.android.countries.CountryPreference
android:key="country"
android:title="..."
android:enabled="true"
android:selectable="true" />
String[] countryCodes = CountryList.getMachineReadable(context);
// countryCodes now contains "CHN", "IND", "USA", "IDN", "BRA" etc.
String[] countryNames = CountryList.getHumanReadable(context);
// countryNames now contains "China", "India", "United States", "Indonesia", "Brazil" etc. (depending on the user's locale)
String localizedName = Country.getNameByIso3Code(context, "ESP");
// localizedName now contains "Spain" or "España" (etc.) depending on the user's locale
- Create a new entry at the end of the string array
countries_list_machineinres/values/short_codes.xml - Add the full name of the country (at least for English) to our platform for managed translations
- Create a new entry at the end of the string array
countries_list_humaninres/values/full_names.xml, referencing the newcountry_xxxresource that has just been submitted in the step before
If you want to translate existing country names, please do so on our platform for managed translations.
Copyright (c) delight.im <info@delight.im>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.