Wannabe
Wannabe

Reputation: 737

EditText directly to TextView

I did some research but I couldn't find the answer to my question. I have a EditText and a TextView in my layout. What I would like to accomplish is that when I type in the EditText, it goes directly into my TextView. I don't know if this is possible. Someone who can help me solve my problem?

Thanks in advance! :)

Upvotes: 1

Views: 57

Answers (3)

Piyush
Piyush

Reputation: 18933

Its too simple you have just implement addTextChangedListener method

uredit.addTextChangedListener(new TextWatcher(){
    public void afterTextChanged(Editable s){
       urtextview.setText(s.toString());
    }

    public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

    public void onTextChanged(CharSequence s, int start, int before, int count) {}
});

Upvotes: 1

Swapnil
Swapnil

Reputation: 654

Ya! It's possible use edit text on change listener so while on change method you can set text to your text view.

Field2.addTextChangedListener(new TextWatcher() {

   public void afterTextChanged(Editable s) {}

   public void beforeTextChanged(CharSequence s, int start,
     int count, int after) {
   }

   public void onTextChanged(CharSequence s, int start,
     int before, int count) {
     Field1.setText("");
   }
  }); 

Upvotes: 0

Joseph Boyle
Joseph Boyle

Reputation: 570

You're going to have to implement a TextWatcher in your onCreate method for the Activity.

EditText editBox = (EditText)findViewById(R.id.edit_box_id);
editBox.addTextChangedListener(new TextWatcher(){
    public void afterTextChanged(Editable s){
        ((TextView)findViewById(R.id.textview_id)).setText(s.toString());
    }

    public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

    public void onTextChanged(CharSequence s, int start, int before, int count) {}
});

Be sure to swap R.id.edit_box_id with the actual EditText field's ID, and R.id.textview_id with the actual TextView id.

Upvotes: 2

Related Questions