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_code
value will be assigned toabc
.When your
CountryCodePicker.OnCountryChangeListener
'sonCountrySelected()
method is being invoked, theccp.getSelectedCountryCodeWithPlus();
's value gets assigned toselected_country_code
. SinceString
is 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.OnCountryChangeListener
anonymous implementation to assign the selected country value toabc
e.g.