Skip to content

Damacustas/AndroidCountryPicker

 
 

Repository files navigation

AndroidCountryPicker

Features

CountryPicker is a simple fragment that can be embedded or shown as dialog. See the example to see more detail.

The functions are simple:

  1. Allow user to search the country

  2. Inform client which country user has selected

  3. Convenient function to get currency code of the selected country

How to embed

Using gradle

Define jitpack.io as a repository

repositories {
	// ...
    maven { url 'https://jitpack.io' }
	// ...
}

Include country picker

dependencies {
	// ...
    compile 'com.github.Damacustas:AndroidCountryPicker:1.0.5'
	// ...
}

How to use

To use CountryPicker in your code as a fragment:

FragmentTransaction transaction = getFragmentManager().beginTransaction();
CountryPicker picker = new CountryPicker();
transaction.replace(R.id.home, picker);
transaction.commit();

To show CountryPicker as a dialog:

CountryPicker picker = CountryPicker.newInstance("Select Country");
picker.show(getFragmentManager(), "COUNTRY_PICKER");

When user selects a country, client can listen to that event:

picker.setListener(new CountryPickerListener() {

	@Override
	public void onSelectCountry(String name, String code) {
		// Invoke your function here
	}
});

To receive the data that the picker uses:

CountryProvider countryProvider = new CountryProvider(context);

Country de = countryProvider.getCountryByCode("DE"); // ignores case
Log.d(de.getName()) // Germany

List<Country> countries = countryProvider.getCountries();

About

The data is from CountryPicker by nicklockwood (https://github.com/nicklockwood/CountryPicker)

I converted his data in "Countries.plist" to json format to avoid extra dependency.

Thanks Nick for his awesome library!

License

See LICENSE.md

About

AndroidCountryPicker without support libraries

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%