Reputation: 1
In my toolbar has a textView which is invisible by default. After user input something in my edittext, the textView should be visible to user. How to implement this?
Upvotes: 0
Views: 58
Reputation: 405
For your editText view, you can add a TextWatcher.
TextWatcher like this:
editText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
int vibility = (TextUtils.isEmpty(charSequence)) ? View.GONE : View.VISIBLE;
textView.setVisibility(vibility);
}
@Override
public void afterTextChanged(Editable editable) {
}
});
Upvotes: 1
Reputation: 1106
You can try this one:
editText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
if(s.length()>0){
toolBarTextView.setVisiblity(View.GONE);
toolBarTextView.setText("");
}else {
toolBarTextView.setVisiblity(View.VISIBLE);
toolBarTextView.setText(s.toString());
}
}
});
Upvotes: 0