Skip to content

Default Country

Harsh Bhakta edited this page Jan 9, 2018 · 3 revisions

Default country

  • If cpp_autoDetectCountry is enabled, the default country will be set when CCP fails to detect country or something goes wrong.
  • If ccp_autoDetectCountry is disabled, the default country will be set automatically when the layout is prepared.

A. Through xml

Add app:ccp_defaultNameCode="US" (replace "US" with your default country name code) to xml layout. Refer list of countries for name codes.

	        <com.hbb20.CountryCodePicker
	         android:id="@+id/ccp"
	         android:layout_width="wrap_content"
	         android:layout_height="wrap_content"
	         app:ccp_defaultNameCode="US"  />
  • The other way of setting default country is using phone code, by app:ccp_defaultPhoneCode="1". Setting default country using phone code is not recommended. There are few cases where more than one countries share the same phone code. This might set unexpected country as default.

app:ccp_defaultNameCode has higher priority than app:ccp_defaultPhoneCode.

B. Programmatically

  • To set default country programmatically, use setDefaultCountryUsingNameCode() method.
  • setDefaultCountryUsingNameCode() or setDefaultCountryUsingPhoneCode() will not set default country as selected country in CCP view. To set default country as selected country in CCP view, call resetToDefaultCountry() method.

If you do not specify default country from xml, IN +91 (India) will be the default country until you update default country programmatically.

Clone this wiki locally