title: One TextField(Edit Text) in java calculator
body: <p>I have this calculator app that works perfectly fine, however, I have two text fields. Num1, and num2. I want to make it only num1, or only one edit text. I have no clue on how to do this, so I hope you guy's can help me. I am currently making this calculator app on android studio, and my acivity main layout is fine. I will include my java code(caution, it's a lot of code):</p>
  
  <pre><code>package com.example.lenovouser.calculator123;
  //IMPORT
  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;
  import android.widget.Toast;
  import android.widget.ToggleButton;
  
  
  public class MainActivity extends AppCompatActivity {
      // ASSIGNING THE NAMES OR VARIABLES
      TextView result, textView8;
      EditText number1, number2;
      Button add,subtract,divide,multiply,squareroot,square,cube,clear,Exponent,percent,sind, cosd, tand;
  ToggleButton switch2, switch3;
  double resultnum = 0.0;
  float num1 = 0, num2 = 0, num3 = 0, p = 0, e = 0;
  
  boolean radiant = false, degree = false;
  
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      //ASSIGNING THE VARIABLES TO THE ANDROID WIDGETS.
      result = (TextView)findViewById(R.id.sum);
      number1 = (EditText)findViewById(R.id.number1);
      number2 = (EditText)findViewById(R.id.number2);
      add = (Button)findViewById(R.id.button);
      subtract = (Button)findViewById(R.id.button2);
      multiply = (Button)findViewById(R.id.button3);
      divide = (Button)findViewById(R.id.button4);
      squareroot =(Button)findViewById(R.id.button6);
      square = (Button)findViewById(R.id.button5);
      clear = (Button)findViewById(R.id.button8);
      Exponent = (Button)findViewById(R.id.button9);
      percent = (Button)findViewById(R.id.button10);
      sind = (Button)findViewById(R.id.button18);
      cosd = (Button)findViewById(R.id.button19);
      tand = (Button)findViewById(R.id.button20);
      switch2 = (ToggleButton) findViewById(R.id.switch2);
      switch3 = (ToggleButton) findViewById(R.id.switch3);
      textView8 = (TextView)findViewById(R.id.textView8);
      cube = (Button)findViewById(R.id.cube);
  
      add.setOnClickListener(new View.OnClickListener() {
  
          @Override
          public void onClick(View v) {
              //ADD
  
              if (number1.getText().length() != 0) {
                  num1 = Float.parseFloat(number1.getText().toString());
  
              }
              if (number2.getText().length() != 0) {
                  num2 = Float.parseFloat(number2.getText().toString());
              }
  
  
              if (num1 == 0){
                  Toast.makeText(getApplicationContext(),"Please enter a number",Toast.LENGTH_SHORT).show();
                  return;
              }
  
              if (num2 == 0){
                  Toast.makeText(getApplicationContext(),"Please enter a number",Toast.LENGTH_SHORT).show();
                  return;
              }
  
              resultnum = num1 + num2;
              result.setText(String.valueOf(resultnum));
          }
      });
  
  
  
  
      subtract.setOnClickListener(new View.OnClickListener(){
          //SUBTRACT
          @Override
          public void onClick(View v){
  
              if (number1.getText().length() != 0)
                  num1 = Float.parseFloat(number1.getText().toString());
              if (number2.getText().length() != 0)
                  num2 = Float.parseFloat(number2.getText().toString());
  
              if (num1 == 0){
                  Toast.makeText(getApplicationContext(),"Please enter a number",Toast.LENGTH_SHORT).show();
                  return;
              }
  
              if (num2 == 0){
                  Toast.makeText(getApplicationContext(),"Please enter a number",Toast.LENGTH_SHORT).show();
                  return;
              }
  
  
              resultnum = num1 - num2;
              result.setText(String.valueOf(resultnum));
          }
      });
  
  
  
  
      multiply.setOnClickListener(new View.OnClickListener(){
          //MULTIPLY
          @Override
          public void onClick(View v){
  
              if (number1.getText().length() != 0)
                  num1 = Float.parseFloat(number1.getText().toString());
              if (number2.getText().length() != 0)
                  num2 = Float.parseFloat(number2.getText().toString());
              if (num1 == 0){
                  Toast.makeText(getApplicationContext(),"Please enter a number",Toast.LENGTH_SHORT).show();
                  return;
              }
  
              if (num2 == 0){
                  Toast.makeText(getApplicationContext(),"Please enter a number",Toast.LENGTH_SHORT).show();
                  return;
              }
  
              resultnum = num1 * num2;
              result.setText(String.valueOf(resultnum));
          }
      });
  
  
  
  
  
      divide.setOnClickListener(new View.OnClickListener(){
          //DIVIDE
          @Override
          public void onClick(View v){
  
              if (number1.getText().length() != 0)
                  num1 = Float.parseFloat(number1.getText().toString());
              if (number2.getText().length() != 0)
                  num2 = Float.parseFloat(number2.getText().toString());
              if (num1 == 0){
                  Toast.makeText(getApplicationContext(),"Please enter a number",Toast.LENGTH_SHORT).show();
                  return;
              }
  
              if (num2 == 0){
                  Toast.makeText(getApplicationContext(),"Please enter a number",Toast.LENGTH_SHORT).show();
                  return;
              }
  
              resultnum = num1 / num2;
              result.setText(String.valueOf(resultnum));
          }
      });
  
  
      squareroot.setOnClickListener(new View.OnClickListener(){
          //SQUAREROOT
          @Override
          public void onClick(View v){
  
              if (number1.getText().length() != 0)
                  num1 = Float.parseFloat(number1.getText().toString());
              if (number2.getText().length() != 0)
                  num2 = Float.parseFloat(number2.getText().toString());
  
              if (num1 == 0){
                  Toast.makeText(getApplicationContext(),"Please enter a number",Toast.LENGTH_SHORT).show();
                  return;
              }
  
  
  
  
              resultnum = (Math.sqrt(num1));
              result.setText(String.valueOf(resultnum));
          }
      });
  
  
      square.setOnClickListener(new View.OnClickListener(){
          //SQUARE
          @Override
          public void onClick(View v){
              if (number1.getText().length() != 0)
                  num1 = Float.parseFloat(number1.getText().toString());
              if (number2.getText().length() != 0)
                  num2 = Float.parseFloat(number2.getText().toString());
  
              if (num1 == 0){
                  Toast.makeText(getApplicationContext(),"Please enter a number",Toast.LENGTH_SHORT).show();
                  return;
              }
  
  
  
  
              resultnum = num1*num1;
              result.setText(String.valueOf(resultnum));
          }
      });
  
  
      cube.setOnClickListener(new View.OnClickListener(){
          //SQUARE
          @Override
          public void onClick(View v){
  
              if (number1.getText().length() != 0)
                  num1 = Float.parseFloat(number1.getText().toString());
              if (number2.getText().length() != 0)
                  num2 = Float.parseFloat(number2.getText().toString());
  
              if (num1 == 0){
                  Toast.makeText(getApplicationContext(),"Please enter a number",Toast.LENGTH_SHORT).show();
                  return;
              }
  
  
  
              resultnum = num1*num1*num1;
              result.setText(String.valueOf(resultnum));
          }
      });
  
  
      clear.setOnClickListener(new View.OnClickListener(){
  
          @Override
          public void onClick(View v){
              //CLEAR
              num1 = (0);
              num2 = (0);
              num3 = (0);
              number1.setText("");
              number2.setText("");
              //txt.setText("");
              resultnum = 0;
              result.setText(String.valueOf(resultnum));
          }
      });
  
  
      Exponent.setOnClickListener(new View.OnClickListener(){
  
          @Override
          public void onClick(View v){
  
              //EXPONENT
  
              if (number1.getText().length() != 0) {
                  p = Float.parseFloat(number1.getText().toString());
              }
              if (number2.getText().length() != 0) {
                  e = Float.parseFloat(number2.getText().toString());
              }
              if (p == 0){
                  Toast.makeText(getApplicationContext(),"Please enter a number",Toast.LENGTH_SHORT).show();
                  return;
              }
              if (e == 0){
                  Toast.makeText(getApplicationContext(),"Please enter a number",Toast.LENGTH_SHORT).show();
                  return;
              }
              resultnum = (Math.pow(p, e));
              p = 0;
              e = 0;
              result.setText(String.valueOf(resultnum));
          }
      });
  
  
  
      percent.setOnClickListener(new View.OnClickListener(){
  
          @Override
          public void onClick(View v){
  
              //PERCENT
              if (number1.getText().length() != 0)
                  num1 = Float.parseFloat(number1.getText().toString());
              if (number2.getText().length() != 0)
                  num2 = Float.parseFloat(number2.getText().toString());
              if (num1 == 0){
                  Toast.makeText(getApplicationContext(),"Please enter a number",Toast.LENGTH_SHORT).show();
                  return;
              }
  
              if (num2 == 0){
                  Toast.makeText(getApplicationContext(),"Please enter a number",Toast.LENGTH_SHORT).show();
                  return;
              }
              num1 = Float.parseFloat(number1.getText().toString());
              num2 = Integer.parseInt(number2.getText().toString());
              float resultnum = num1 * num2 / 100;
              result.setText(String.valueOf(resultnum));
          }
      });
  
  
  
  
      sind.setOnClickListener(new View.OnClickListener(){
  
          @Override
          public void onClick(View v){
  
              //SIN num2
              if (number1.getText().length() != 0)
                  num1 = Float.parseFloat(number1.getText().toString());
              if (number2.getText().length() != 0)
                  num2 = Float.parseFloat(number2.getText().toString());
              if (num1 == 0){
                  Toast.makeText(getApplicationContext(),"Please enter a number",Toast.LENGTH_SHORT).show();
                  return;
              }
  
  
              if (degree = true)
              {
                  num1 = Integer.parseInt(number1.getText().toString());
                  //num2 = Integer.parseInt(number2.getText().toString());
                  resultnum = Math.sin(Math.toDegrees(num1));
                  result.setText(String.valueOf(resultnum));
              }
  
              if (radiant = true){
                  num1 = Integer.parseInt(number1.getText().toString());
                  //num2 = Integer.parseInt(number2.getText().toString());
                  resultnum = Math.sin(Math.toRadians(num1));
                  result.setText(String.valueOf(resultnum));
  
                  if (degree = false)
                  {
                      Toast.makeText(getApplicationContext(),"Please choose degree or radiant",Toast.LENGTH_SHORT).show();
                      return;
                  }
  
                  if (radiant = false){
                      Toast.makeText(getApplicationContext(),"Please choose degree or radiant",Toast.LENGTH_SHORT).show();
                      return;
                  }
              }
          }
      });
  
  
      cosd.setOnClickListener(new View.OnClickListener(){
  
          @Override
          public void onClick(View v) {
              if (number1.getText().length() != 0)
                  num1 = Float.parseFloat(number1.getText().toString());
              if (number2.getText().length() != 0)
                  num2 = Float.parseFloat(number2.getText().toString());
              if (num1 == 0){
                  Toast.makeText(getApplicationContext(),"Please enter a number",Toast.LENGTH_SHORT).show();
                  return;
              }
  
  
              //COS num2
              if (degree = true)
              {
                  num1 = Integer.parseInt(number1.getText().toString());
                  // num2 = Integer.parseInt(number2.getText().toString());
                  resultnum = Math.cos(Math.toDegrees(num1));
                  result.setText(String.valueOf(resultnum));
              }
  
              if (radiant = true){
                  num1 = Integer.parseInt(number1.getText().toString());
                  //num2 = Integer.parseInt(number2.getText().toString());
                  resultnum = Math.cos(Math.toRadians(num1));
                  result.setText(String.valueOf(resultnum));
  
              }
  
              if (degree = false)
              {
                  Toast.makeText(getApplicationContext(),"Please choose degree or radiant",Toast.LENGTH_SHORT).show();
                  return;
              }
  
              if (radiant = false){
                  Toast.makeText(getApplicationContext(),"Please choose degree or radiant",Toast.LENGTH_SHORT).show();
                  return;
              }
          }
  
      });
  
  
      tand.setOnClickListener(new View.OnClickListener(){
  
          @Override
          public void onClick(View v){
              if (number1.getText().length() != 0)
                  num1 = Float.parseFloat(number1.getText().toString());
              if (number2.getText().length() != 0)
                  num2 = Float.parseFloat(number2.getText().toString());
  
              //TAN num2
              if (num1 == 0){
                  Toast.makeText(getApplicationContext(),"Please enter a number",Toast.LENGTH_SHORT).show();
                  return;
              }
  
  
              if (degree =true)
              {
                  num1 = Integer.parseInt(number1.getText().toString());
                  //num2 = Integer.parseInt(number2.getText().toString());
                  resultnum = Math.tan(Math.toDegrees(num1));
                  result.setText(String.valueOf(resultnum));
              }
  
              if (radiant=true){
                  num1 = Integer.parseInt(number1.getText().toString());
                  // num2 = Integer.parseInt(number2.getText().toString());
                  resultnum = Math.tan(Math.toRadians(num1));
                  result.setText(String.valueOf(resultnum));
  
              }
  
  
  
              if (degree=false)
              {
                  Toast.makeText(getApplicationContext(),"Please choose degree or radiant",Toast.LENGTH_SHORT).show();
                  return;
              }
  
              if (radiant = false){
                  Toast.makeText(getApplicationContext(),"Please choose degree or radiant",Toast.LENGTH_SHORT).show();
                  return;
              }
          }
      });
  
  
      switch2.setOnClickListener(new View.OnClickListener(){
  
          @Override
          public void onClick(View v){
  
              //switchR
              radiant = true;
              degree = false;
  
              textView8.setText(("Radians MODE"));
          }
      });
  
      switch3.setOnClickListener(new View.OnClickListener(){
  
          @Override
          public void onClick(View v){
  
              //switchD
              degree = true;
              radiant = false;
              textView8.setText(("Degree MODE"));
          }
      });
  
  
  }}
  </code></pre>