In my app I was using EditText. I would like to assign numberOfYearsBirthday=0 when there is no text in the edittext.
I have tried the following code and debugged. I have seen that even if my charSequence="" but it ignore the statement and move to the else statement and thus cause error and crash my app assigning null value as an integer.
xB1.addTextChangedListener(new TextWatcher(){
@Override
public void onTextChanged(CharSequence charSequence, int start, int before, int count) {
if(String.valueOf(charSequence)==null){
numberOfYearsBirthday=0;
}else{numberOfYearsBirthday= Integer.valueOf(charSequence.toString());
}
I have also tried the following code
charSequence.toString()==""
Moreover, the following one too
charSequence ==""
but the program is overlooking my if statement. What's the wrong I am doing here?