I'm using textChangedListener on an edit text to show/hide a floating action button.
Everything pretty much works as expected. If edit text is not empty then show fab, if empty then hide fab.
However I have noticed that while using backspace, to delete entered text, deleting the first space triggers the hide fab, then quickly fab shows, since editText is not empty.
I have looked around and haven't seen anything regarding this. So I must be doing something wrong, but I'm not sure what.
Below is my implementation. I have tried and all give me the same behavior
if(editText.getText().toString().isEmpty())
if(editText.getText().toString().length()==0))
if(editText.getText().toString().equals("")
editText.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
Log.d(TAG, "TEXT CHANGED onTextChanged" + editText.getText().toString());
// TODO Auto-generated method stub
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
Log.d(TAG, "TEXT CHANGED beforeTextChanged" + editText.getText().toString());
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
Log.d(TAG, "TEXT CHANGED afterTextChanged" + editText.getText().toString());
// s = editText.getText().toString(); editText.getText().toString()
if (s.toString().isEmpty()) {
fab.setVisibility(View.INVISIBLE);
fab.setAnimation(slideDownAnim);
slideDownAnim.start();
}else{
fab.setVisibility(View.VISIBLE);
fab.setAnimation(slideUpAnim);
slideUpAnim.start();
}
// TODO Auto-generated method stub
}
});
Thanks in advance
***UPDATE**** Found answer which solves my problem here. TextWatcher events are being fired multiple times