Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/takuseno/android-countrylist
This library is Android library for using country names and 2-alphabet codes
https://github.com/takuseno/android-countrylist
Last synced: about 1 month ago
JSON representation
This library is Android library for using country names and 2-alphabet codes
- Host: GitHub
- URL: https://github.com/takuseno/android-countrylist
- Owner: takuseno
- License: apache-2.0
- Created: 2015-07-02T11:55:02.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-07-25T09:49:43.000Z (over 9 years ago)
- Last Synced: 2024-10-23T04:07:05.512Z (2 months ago)
- Language: Java
- Size: 434 KB
- Stars: 5
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# android-countrylist
This library is Android library for using country names and 2-alphabet codes##Usage
Add repository to your build.gradle
```gradle
repositories {
maven { url {'https://raw.github.com/takuseno/android-countrylist/master/repository'}}
}dependencies {
compile 'jp.gr.java_conf.androtaku.countrylist:countrylist:1.1.0'
}
```In your Java code
```java
//get all countries as objects that contain name and 2-alphabet code
List countries = CountryList.getCountries(context);//get all country names as string list
List countryNames = CountryList.getCountryNames(context);//get all country 2-alphabet code as string list
List countryCodes = CountryList.getCountryCodes(context);//convert country name into 2-alphabet code
String code = CountryList.convertNameToCode(context, "Japan");
// in this case, code is "JP"//convert country 2-alphabet code into name
String name = Country.convertCodeToName(context, "JP");
//in this case, name is "Japan"//get Country object by country name
Country country = CountryList.getCountryByName(context, "Japan");//get Country object by country 2-alphabet code
Country country = CountryList.getCountryByCode(context, "JP");
```Now, English and Japanese country data files are available.
If you change name language, you should use following code.
```java
CountryList.dataLanguage = DataLanguage.Japanese;
List countries = CountryList.getCountries(context);
```##Country List
If you add other countries, please modify [country_code.csv](https://github.com/takuseno/android-countrylist/blob/master/countrylist/src/main/res/raw/country_code.csv).And if you add other language data file, you have to check out "CountryList.getFileId".