title: How to set ontime user input text from EditView to TextView without clicking the button
body: <p>I was doing practice and I am stuck at one point that I want to set ontime user input text from EditText to TextView but I don't know how can I do this so I search it here and I found this <a href="https://stackoverflow.com/questions/48067033/how-to-get-edittext-value-to-textview-at-the-time-of-typing-without-button-click">How to get EditText value to TextView at the time of typing without button click in android [closed]
  </a>
  I follow this but it is not working so that I decided to post a new question to know if any improvement is there or not.</p>
  <p>here is my simple XML</p>
  <pre><code>&lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
  xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
  xmlns:tools=&quot;http://schemas.android.com/tools&quot;
  android:layout_width=&quot;match_parent&quot;
  android:layout_height=&quot;match_parent&quot;
  android:background=&quot;#fff&quot;
  android:orientation=&quot;vertical&quot;
  android:padding=&quot;10dp&quot;
  tools:context=&quot;.MainActivity&quot;&gt;
  
  &lt;TextView
      android:id=&quot;@+id/tv1&quot;
      android:layout_width=&quot;wrap_content&quot;
      android:layout_height=&quot;wrap_content&quot;
      android:layout_gravity=&quot;center_horizontal&quot;
      android:layout_marginTop=&quot;40dp&quot;
      android:text=&quot;Hello World!&quot;
      android:textColor=&quot;#000&quot;
      android:textSize=&quot;20sp&quot; /&gt;
  
  &lt;TextView
      android:id=&quot;@+id/tv2&quot;
      android:layout_width=&quot;wrap_content&quot;
      android:layout_height=&quot;wrap_content&quot;
      android:layout_gravity=&quot;center_horizontal&quot;
      android:layout_marginTop=&quot;20dp&quot;
      android:text=&quot;Hello World!&quot;
      android:textColor=&quot;#000&quot;
      android:textSize=&quot;20sp&quot; /&gt;
  
  &lt;EditText
      android:id=&quot;@+id/et1&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;wrap_content&quot;
      android:layout_marginTop=&quot;20dp&quot;
      android:inputType=&quot;text&quot; /&gt;
  
  &lt;EditText
      android:id=&quot;@+id/et2&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;wrap_content&quot;
      android:layout_marginTop=&quot;20dp&quot;
      android:inputType=&quot;text&quot; /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  <p>This is my java code</p>
  <pre><code>package com.example.ontimedata;
  
  import androidx.appcompat.app.AppCompatActivity;
  import android.os.Bundle;
  import android.text.Editable;
  import android.text.TextWatcher;
  import android.util.Log;
  import android.widget.EditText;
  import android.widget.TextView;
  
  public class MainActivity extends AppCompatActivity {
  
  TextView tv1, tv2;
  EditText et1, et2;
  String data1, data2;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      tv1 = findViewById(R.id.tv1);
      tv2 = findViewById(R.id.tv2);
      et1 = findViewById(R.id.et1);
      et2 = findViewById(R.id.et2);
  
      TextWatcher textWatcher = new TextWatcher() {
          @Override
          public void beforeTextChanged(CharSequence s, int start, int count, int after) {
              Log.d(&quot;TAG&quot;, &quot;beforeTextChanged: &quot;);
              data1 = et1.getText().toString();
          }
  
          @Override
          public void onTextChanged(CharSequence s, int start, int before, int count) {
              Log.d(&quot;TAG&quot;, &quot;onTextChanged: &quot;);
              data1 = et1.getText().toString();
          }
  
          @Override
          public void afterTextChanged(Editable s) {
              Log.d(&quot;TAG&quot;, &quot;afterTextChanged: &quot;);
              data1 = et1.getText().toString();
          }
      };
      tv1.addTextChangedListener(textWatcher);
      Log.d(&quot;TAG&quot;, &quot;onCreate: &quot;);
  
  
      TextWatcher textWatcher1 = 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) {
              data2 = et2.getText().toString();
          }
  
          @Override
          public void afterTextChanged(Editable s) {
  
          }
      };
      tv2.addTextChangedListener(textWatcher1);
  }
  }
  </code></pre>
  <p>Thanks in advance if you answered this.</p>