CountryPicker

CountryPicker is an Android library created to show a custom fragment which allows to choose a country.

Screenshots

Demo Screenshot

Installation

Add CountryPicker dependency to your build.gradle


dependencies {
  compile 'com.juanpabloprado:countrypicker:1.2.0'
}

Or add CountryPicker as a new dependency inside your pom.xml


<dependency>
  <groupId>com.juanpabloprado</groupId>
  <artifactId>countrypicker</artifactId>
  <version>1.2.0</version>
  <type>aar</type>
</dependency>

How to use

To embed CountryPicker in your own activity:

getSupportFragmentManager().beginTransaction()
        .replace(R.id.container,
            CountryPicker.getInstance(new CountryPickerListener() {
              @Override public void onSelectCountry(String name, String code) {
                Toast.makeText(MainActivity.this, "Name: " + name, Toast.LENGTH_SHORT).show();
              }
            }))
        .commit();

To show CountryPicker as a dialog:

CountryPicker picker = CountryPicker.getInstance("Select Country", new CountryPickerListener() {
  @Override public void onSelectCountry(String name, String code) {
    Toast.makeText(getActivity(), "Name: " + name, Toast.LENGTH_SHORT).show();
    DialogFragment dialogFragment =
        (DialogFragment) getSupportFragmentManager().findFragmentByTag("CountryPicker");
    dialogFragment.dismiss();
  }
});
picker.show(getSupportFragmentManager(), "CountryPicker");

Developed By

Follow me on Twitter

Add me to Linkedin

License

Copyright 2015 Juan Pablo Prado

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.