Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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".