I'm going to start a new project, in which the user writes in an edittext and automatically what it says is reflected in the textview.
Can you think of a way to carry it out?
I'm going to start a new project, in which the user writes in an edittext and automatically what it says is reflected in the textview.
Can you think of a way to carry it out?
Using TextWatcher:
tuEdittext.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void afterTextChanged(Editable s) {
if(editText.getText().length() >= 0) {
tuTextView.setText(editText.getText().toString())
}
}
});
The correct way is through TextWatcher and simply it validates that the length of the text entered in EditText
is different from 0 to add the text in TextView
.
myEditText.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {}
@Override
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start,
int before, int count) {
if(s.length() != 0)
myTextView.setText(myEditText.getText().toString());
}
});