I use the CountryCodePicker from the CountryCodePickerProject by hbb20.
I get the User's data from the DataBase, and sometimes for whatever reason the User has "" (empty string) saved as their country.
I use this Picker to edit their country, and if the User does not change his country then I get India "IN" as the selectedCCPCountry since the defaultCCPCountry automatically returns India if no country was set.
How can I set the selectedCCPCountry or some other flag to null or "" so that in this case I can know not to change the User's data?
Thanks!
So I created an issue for this on GitHub and got a quick response from the author:
It seems like your primary use case is to select country without phone
number validation, did I get that right? if so, you should try Android
Country Picker (https://github.com/hbb20/AndroidCountryPicker). It has out
of box support for non selection and much more. Please let me know if that
works for you.
Here is my response and my temporary workaround:
As I don't want to undo all the code I have already, I made a temporary workaround.
mCountryChangedByUser is false and turns true only when a country is selected inside the CountryCodePicker.
mCountryCCP.setOnCountryChangeListener(new CountryCodePicker.OnCountryChangeListener() {
#Override
public void onCountrySelected() {
mCountryChangedByUser = true;
mCountryTextTV.setText(mCountryCCP.getSelectedCountryName());
mUser.setCountry(mCountryCCP.getSelectedCountryNameCode());
}
});
If the user did not change his country then just return the original country in my saveUser() function.
if (mCountryChangedByUser) {
userUpdate.setCountry(mCountryCCP.getSelectedCountryNameCode() );
} else {
userUpdate.setCountry(mUser.getCountry());
}
Maybe next time I'll use the AndroidCountryPicker.
Thanks!
Related
I am trying to make three input edit texts that depend on each other i.e Country, State, City that depend on each other in kotlin android. I want when country is picked in the country input, the states in the selected country should show in the state input.
Any one with an idea how i can achieve this?
I am new to Kotlin and have no idea where to start from
Use conditional the check whether country is selected or not
if(condition){
// condition is true
// You can show and hide views by using: findViewById<EditText>(R.id.myeditText).visibility = View.GONE or View.Visible
} else {
// condition is true
}
These statements will be your best friend
I want the user to type in his or her Facebook account-link (don't have a better solution atm).
Now, when the user clicks the edittext it is supposed to say : "www.facebook.com/". Now the cursor is supposed to be at the END of the edittext (after the "/") and the user is not supposed to delete the first letters so that the "www.facebook.com/" stays exactly where it is. This will have the user to ONLY type in his or her facebook name and therefore connect the profile.
Is there a way of doing this?
Thank you :)
You can do that by using the event "TextChanged" and in your code validate if the size is big than your string, like that:
if (((EditText)sender).Text.Length >= 17)
{
((EditText)sender).Text = e.NewTextValue;
}
else
{
((EditText)sender).Text = "www.facebook.com/";
}
So if the value is bigger than your string you will replace that for the value, if not you just set the value with your string
I want to check if user with email authentication has a phone number set in user profile.
I try if(user.getPhoneNumber() == null{
//do this
}
but it is not working for me... So i want to know what is default value of it
or how can i make it in another way. Thank you :)
user.getPhoneNumber() returns a String. The default value is an empty String which is not null. Use either
if(TextUtils.isEmpty(user.getPhoneNumber())){
//do this
}
or
if("".equals(user.getPhoneNumber())){
//do this
}
I am allowing user to register with mobile number only and i wanna validate number in app without using internet, what i wanna do is that get valid phone number length of country selected by user , validate it with length and formatting of number in that country's format.
for e.g. length of India's phone number is 10 and format is 0**********
Please tell me how to do that.
Add Following Code.
In gradle
compile 'com.googlecode.libphonenumber:libphonenumber:8.5.2'
In Activity class
PhoneNumberUtil phoneNumberUtil = PhoneNumberUtil.getInstance();
String isoCode = phoneNumberUtil.getRegionCodeForCountryCode(Integer.parseInt(countryCode));
String exampleNumber= String.valueOf(phoneNumberUtil.getExampleNumber(isoCode).getNationalNumber());
int phoneLength=exampleNumber.length();
editTextLoginPhone.setFilters( new InputFilter[] {
new InputFilter.LengthFilter(phoneLength)});
Hope this code will help you.
if you not want to use the internet of checking the number valid or not , you can do programmatically though its long but solution can be this only .
Go to link : https://en.wikipedia.org/wiki/List_of_mobile_phone_number_series_by_country
and do programmatically the validation with conditions.
You can try this code for Indian Phone numbers:-
private static boolean isValidPhoneNumber(String mobile) {
String regEx = "^[0-9]{10}$";
return mobile.matches(regEx);
}
you should force user to enter the country code and you can validate the phone number also just go through the links below
https://github.com/googlei18n/libphonenumber
and
List of phone number country codes
I have contact like "+919672525253".Now i extract the country code like "91" from that number.Now if number is like "9672525253" and if i extract the country code then it will give me "967".So after extracting the country code how can i check that remaining number is valid mobile number for that country code or not?
EDIT
If any body know the mobile number length country wise then also i can solve this problem.like in india 10 digits.
You pretty much can't. For example in the US mobile numbers and landline numbers are indistinguishable, they have normal area codes just like landline numbers. Even if it were possible every country does it differently and it is also constantly changing as numbers run out new prefixes are added and things change and their is no pattern you could match against or database you could do a lookup against.
Take a look at libPhoneNumber (bundled in ICS) which can help validating a phone number (see PhoneNumberUtils).
There's a MobileType you can get after validation but as stated in the source and by Ben, in some region this will not work.
EDIT:
Some validation code (here we need to check the phone is a valid one assuming it's a french one):
boolean isValid = false;
PhoneNumber number = null;
try {
number = this.phoneUtil.parse(phone, "FR"); // phone is number in internationnal format "+xxxxxx"
isValid = this.phoneUtil.isValidNumber(number);
} catch (final NumberParseException e) {
// ...
}
isValid // is the phone number valid according to the library?
this.phoneUtil.getRegionCodeForNumber(number); // this gets the country code of the phone as found by the library (for example "US", "CH", "GB", ...)
This works for us but you'll need to try it to see if it suit your need.