GithubHelp home page GithubHelp logo

androidcountrypicker's Introduction

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.SocialbitGmbH:AndroidCountryPicker:1.0.3@aar'
	// ...
}

Note the library requires 'com.android.support:support-v4'

If you want to use the country auto-selection based on the user locatiion you must put this permission in your app manifest:

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

How to use

To use CountryPicker in your code as a fragment:

FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
//The second parameter determines if the country must be auto-selected from the user current location.
CountryPicker picker = CountryPicker.newInstance(null, true);
transaction.replace(R.id.home, picker);
transaction.commit();

To show CountryPicker as a dialog:

//The second parameter determines if the country must be auto-selected from the user current location.
CountryPicker picker = CountryPicker.newInstance("Select Country", true);
picker.show(getSupportFragmentManager(), "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("ES"); // ignores case
Log.d(de.getName()) // Spain

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!

Thanks to Javi for the Spanish translation (https://github.com/Mun0n/AndroidCountryPicker)

License

See LICENSE.md

androidcountrypicker's People

Contributors

thomasdao avatar michiruf avatar coffeeworks avatar

Watchers

James Cloos avatar David Perez Camacho avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.