title: onClickListener for a button text to change based on edit text
body: <p>I have the following code but it changes the button text to empty. I'm basically trying to change the the button's text when it clicked to whatever the user types into the edit text field I have. Everything seems to work, however, when I click on either buttons I have the button's text changes to empty/null and since i'm using wrap content it shrinks the size of the button too.</p>
  
  <p>activity_main.xml
      
      </p>
  
  <pre><code>    &lt;LinearLayout
          android:layout_width="368dp"
          android:layout_height="495dp"
          android:orientation="vertical"
          tools:layout_editor_absoluteX="8dp"
          tools:layout_editor_absoluteY="8dp"&gt;
  
      &lt;TextView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:background="#0000ff"
              android:gravity="center"
              android:padding="10dp"
              android:text="Name: Balkar Rana"
              android:layout_marginLeft="30dp"
              android:layout_marginTop="30dp"
              android:textColor="#FFFF00"
              android:textSize="20dp"
              android:textStyle="bold"
              /&gt;
  
      &lt;LinearLayout
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginTop="25dp"
          android:orientation="horizontal"&gt;
  
          &lt;TextView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginLeft="30dp"
              android:textColor="#FF69B4"
              android:text="Username: "
              android:textSize="20dp"/&gt;
  
          &lt;EditText
              android:layout_width="200dp"
              android:layout_height="wrap_content"
              android:gravity="left"
              android:textColor="#000000"
              android:textSize="20dp"
              android:id="@+id/username"/&gt;
  
      &lt;/LinearLayout&gt;
  
      &lt;LinearLayout
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginTop="25dp"
          android:orientation="horizontal"&gt;
  
          &lt;TextView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginLeft="30dp"
              android:textColor="#63ea1f"
              android:text="Password: "
              android:textSize="20dp"/&gt;
  
          &lt;EditText
              android:inputType="textPassword"
              android:layout_width="200dp"
              android:layout_height="wrap_content"
              android:gravity="left"
              android:textColor="#000000"
              android:textSize="20dp"
              android:id="@+id/password"/&gt;
  
  
      &lt;/LinearLayout&gt;
  
      &lt;LinearLayout
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:orientation="vertical"
          android:layout_marginTop="25dp"&gt;
  
          &lt;Button
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginLeft="30dp"
              android:text="Username"
              android:textSize="20dp"
              android:textStyle="bold"
              android:textColor="#FF69B4"
              android:id="@+id/userButton"
              android:onClick="onClick"/&gt;
          &lt;Button
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginLeft="30dp"
              android:layout_marginTop="10dp"
              android:text="Password"
              android:textSize="20dp"
              android:textStyle="bold"
              android:textColor="#63ea1f"
              android:id="@+id/passButton"
              android:onClick="onClick"/&gt;
          &lt;Button
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginLeft="30dp"
              android:layout_marginTop="10dp"
              android:text="USER-PASS"
              android:textSize="20dp"
              android:textStyle="bold"
              android:textColor="#FF69B4"
              android:id="@+id/userPassButton"
              android:onClick="onClick"/&gt;
  
      &lt;/LinearLayout&gt;
  
  
      &lt;/LinearLayout&gt;
  
  &lt;/android.support.constraint.ConstraintLayout&gt;
  </code></pre>
  
  <p>MainActivity.java</p>
  
  <pre><code>    package com.example.balkarrana.lab2;
  
      import android.content.Intent;
      import android.support.v7.app.AppCompatActivity;
      import android.os.Bundle;
      import android.view.View;
      import android.widget.Button;
      import android.widget.EditText;
      import android.widget.TextView;
  
      public class MainActivity extends AppCompatActivity{
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          EditText usernameInput = (EditText)findViewById(R.id.username);
          final String userText = usernameInput.getText().toString();
          final Button userButtonVariable = (Button)findViewById(R.id.userButton);
  
          EditText passwordInput = (EditText)findViewById(R.id.username);
          final String passText = passwordInput.getText().toString();
          final Button passButtonVariable = (Button)findViewById(R.id.passButton);
  
          final String userPassText = userText + passText;
          final Button userPassButtonVariable = (Button)findViewById(R.id.userPassButton);
  
          userButtonVariable.setOnClickListener(new View.OnClickListener() {
              public void onClick(View v) {
                  userButtonVariable.setText(userText);
              }
          });
  
          passButtonVariable.setOnClickListener(new View.OnClickListener() {
              public void onClick(View v) {
                  passButtonVariable.setText(passText);
              }
          });
  
          userPassButtonVariable.setOnClickListener(new View.OnClickListener() {
              public void onClick(View v) {
                  userPassButtonVariable.setText(userPassText);
              }
          });
      }
  
      }
  </code></pre>