I am working on an app in which users have to select a country code, i was successful in creating a spinner for the said purpose as shown in this link:
Creating a spinner for choosing country code
But i am getting problem in reading the value selected in the spinner.
{
String abc = onCountryPickerClick();//abc is always null
}
public String onCountryPickerClick (){
ccp.setOnCountryChangeListener(new CountryCodePicker.OnCountryChangeListener() {
@Override
public void onCountrySelected() {
selected_country_code = ccp.getSelectedCountryCodeWithPlus();
}
});
return selected_country_code;
}
When
String abc = onCountryPickerClick();is being invoked, theselected_country_codevalue will be assigned toabc.When your
CountryCodePicker.OnCountryChangeListener'sonCountrySelected()method is being invoked, theccp.getSelectedCountryCodeWithPlus();'s value gets assigned toselected_country_code. SinceStringis immutable, changingselected_country_code's value won't change the value ofabc, nor thereturn selected_country_code;will be invoked.One of possible solutions would be to change your
CountryCodePicker.OnCountryChangeListeneranonymous implementation to assign the selected country value toabce.g.