title: Change the value of EditText with onClick Button?
body: <p>In main.xml I made a row containing a TextView, an EditText and a "+" and "-" button.</p>
  
  <p>Underneath that I made an "Add" button that will help you create a new row When you click the add button, you get an EditText and a Submit and Cancel button.</p>
  
  <p>On "Submit" it outputs the EditText value to the TextView and creates the same row as the first one. </p>
  
  <p>The numeric value "NewValueBox" should +1 when the "+" button is pressed.
  But because I call it in another function it is not recognized by createNewAddButton() function in which the button is set up.</p>
  
  <p>So in short:
  "How do I change the value of NewValueBox when I click NewAddButton?"</p>
  
  <p>Here's the code:</p>
  
  <pre><code>package com.lars.MyApp;
  
  import com.google.ads.*;
  import com.lars.MyApp.R;
  
  import android.app.Activity;
  import android.os.Bundle;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.LinearLayout;
  import android.widget.TableLayout;
  import android.widget.TableRow;
  import android.widget.TextView;
  import android.text.InputType;
  import android.view.View;
  import android.view.View.OnClickListener;
  
  public class DrinkRecOrderActivity extends Activity {
  
      int currentValue1 = 0;
      int currentValueNew = 0;
  
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
  
          final EditText firstValue = (EditText) findViewById(R.id.firstValue);
          Button valuePlus = (Button) findViewById(R.id.valuePlus);
          Button valueMinus = (Button) findViewById(R.id.valueMinus);
  
          final Button addValue = (Button) findViewById(R.id.add);
  
          final TableLayout tableLayout1 = (TableLayout) findViewById(R.id.tableLayout1);
          final LinearLayout addValueRow = (LinearLayout) findViewById(R.id.addValueRow);
  
          final EditText addNewValue = (EditText) findViewById(R.id.addNewValue);
          final Button submitNewValue = (Button) findViewById(R.id.submitNewValue);
          final Button cancelNewValue = (Button) findViewById(R.id.cancelNewValue);
  
          // BEGIN ONCLICKLISTENERS
          valuePlus.setOnClickListener(new OnClickListener() {
              public void onClick(View v) {
                  plusValue();
                  firstValue.setText("" + currentValue1);
              }
          });
  
          valueMinus.setOnClickListener(new OnClickListener() {
              public void onClick(View v) {
                  minValue();
                  firstValue.setText("" + currentValue1);
              }
          });     
  
          addValue.setOnClickListener(new OnClickListener() {
              public void onClick(View v) {
                  addValueRow.setVisibility(View.VISIBLE);
                  addValue.setVisibility(View.GONE);
              }
          });
  
          cancelNewValue.setOnClickListener(new OnClickListener() {
              public void onClick(View v) {
                  addValueRow.setVisibility(View.GONE);
                  addValue.setVisibility(View.VISIBLE);
              }
          });
  
          submitNewValue.setOnClickListener(new OnClickListener() {
              public void onClick(View v) {
                  tableLayout1.addView(createnewRow());
                  addValueRow.setVisibility(View.GONE);
                  addValue.setVisibility(View.VISIBLE);
                  addNewValue.setText("");
              }
          });
  
          // END ONCLICKLISTENERS
  
          // Look up the AdView as a resource and load a request.
          AdView adView = (AdView) this.findViewById(R.id.adView);
          adView.loadAd(new AdRequest());
      }
  
      public TableRow createNewRow() {
          final TableRow newRow = new TableRow(this);
          final EditText addNewValue = (EditText) findViewById(R.id.addNewValue);
          newRow.addView(createNewTextView(addNewValue.getText().toString()));
          newRow.addView(createNewValueBox());
          newRow.addView(createNewAddButton());
          newRow.addView(createNewMinusButton());
          return newRow;
      }
  
      public TextView createNewTextView(String text) {
          final TextView textView = new TextView(this);
          textView.setText(text);
          return textView;
      }
  
      public EditText createNewValueBox() {
          EditText NewValueBox = new EditText(this);
          NewValueBox.setHint("0");
          NewValueBox.setInputType(InputType.TYPE_CLASS_NUMBER);
          return NewValueBox;
      }
  
      public Button createNewAddButton() {
          final Button NewAddButton = new Button(this);
  
          NewAddButton.setText("+");
  
          NewAddButton.setOnClickListener(new OnClickListener() {
              public void onClick(View v) {
                  plusNew();
  
                  //NewValueBox.setText("" + currentValueNew);
              }
  
          });
  
          return NewAddButton;
      }
  
      public Button createNewMinusButton() {
          final Button NewMinusButton = new Button(this);
          NewMinusButton.setText("-");
          return NewMinusButton;
      }
  
      // BEGIN PLUS AND MIN FUNCTIONS
  
      public void plusNew() {
          if (currentValueNew &lt;= 999) {
              currentValueNew = currentValueNew + 1;
          }
      }
  
      public void plusValue() {
          if (currentValue1 &lt;= 999) {
              currentValue1 = currentValue1 + 1;
          }
      }
  
      public void minValue() {
          if (currentValue1 &gt;= 1) {
              currentValue1 = currentValue1 - 1;
          }
      }
  
      // END PLUS AND MIN FUNCTIONS
  
  }
  </code></pre>