roa.tah
roa.tah

Reputation: 567

text view in android can't be changed

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

Answers (3)

nstosic
nstosic

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

eulloa
eulloa

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

user2511882
user2511882

Reputation: 9152

You could do something like this:

    if (textCity.getText().toString().trim().length() == 0) {
                cityText.setText("something");
    }
    else
      cityText.setText(textCity); 

Upvotes: 1

Related Questions