Reputation: 567
I have TextView
in my code. I want to test if an EditText
is empty then fill the TextView
with "some thing" or take the text from the EditText
; but it doesn't change the text. Here is the code(in onCreate()
method):
if ((textCity.length())==0){
cityText.setText("something");
}
else
cityText.setText(textCity);
where textCity
textCity=editText1.getText();
and cityText is the TextView
Upvotes: 0
Views: 65
Reputation: 2614
I assume that you haven't invoked it in the right place. You need to place a TextWatcher
on your EditText
. Try this out:
editText1.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
cityText.setText(String.valueOf(s));
}
});
Upvotes: 1
Reputation: 242
Try this
if ((textCity.length() < 0)){
cityText.setText("something");
}
textCity=editText1.getText().toString(); //add this when you're grabbing the text from the //textview
Upvotes: 1
Reputation: 9152
You could do something like this:
if (textCity.getText().toString().trim().length() == 0) {
cityText.setText("something");
}
else
cityText.setText(textCity);
Upvotes: 1