title: Android app - Inputting integers from buttons depending on number of presses
body: <p>I'm writing a calculator app for android using android studio. I want to used 4 buttons for inputting values and functions. However the way I am currently doing it takes the input from the text written on the button. So for my button 1/2/3 when this is pressed 1/2/3 is passed to the textView. </p>
  
  <p>Below is my MainActivity: </p>
  
  <pre><code>   package com.example.myfirstapp;
  
  import android.media.MediaPlayer;
  import android.support.v7.app.ActionBarActivity;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.MediaController;
  import android.widget.TextView;
  
  
  public class MainActivity extends ActionBarActivity  {
      private int[] operatorButtons = {R.id.operators};
      private int[] numericButtons = {R.id.onetwothree, R.id.fourfivesix, R.id.seveneightninezero};
      private boolean  lastNumeric, stateError;
      private TextView txtScreen;
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          // Find the TextView
          this.txtScreen = (TextView) findViewById(R.id.txtScreen);
          // Find and set OnClickListener to numeric buttons
          setNumericOnClickListener();
          // Find and set OnClickListener to operator buttons, equal button and decimal point button
          setOperatorOnClickListener();
      }
  
  
      private void setNumericOnClickListener() {
          // Create a common OnClickListener
          View.OnClickListener listener = new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  // Just append/set the text of clicked button
                  Button button = (Button) v;
                  if (stateError) {
                      // If current state is Error, replace the error message
                      txtScreen.setText(button.getText());
                      stateError = false;
                  } else {
                      // If not, already there is a valid expression so append to it
                      txtScreen.append(button.getText());
                  }
                  // Set the flag
                  lastNumeric = true;
              }
          };
          // Assign the listener to all the numeric buttons
          for (int id : numericButtons) {
              findViewById(id).setOnClickListener(listener);
          }
      }
  
      private void setOperatorOnClickListener() {
          // Create a common OnClickListener for operators
          View.OnClickListener listener = new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  // If the current state is Error do not append the operator
                  // If the last input is number only, append the operator
                  if (lastNumeric &amp;&amp; !stateError) {
                      Button button = (Button) v;
                      txtScreen.append(button.getText());
                      lastNumeric = false;
  
                  }
              }
          };
          // Assign the listener to all the operator buttons
          for (int id : operatorButtons) {
              findViewById(id).setOnClickListener(listener);
          }
  
  
          // Equal button
          /*findViewById(R.id.btnEqual).setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  onEqual();
              }
          });*/
      }
  }
  </code></pre>
  
  <p>and my activity_main:</p>
  
  <pre><code>  &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"&gt;
  
      &lt;TextView
          android:id="@+id/txtScreen"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_alignParentTop="true"
          android:layout_centerHorizontal="true"
          android:gravity="right|center_vertical"
          android:maxLength="16"
          android:padding="10dp"
          android:textAppearance="?android:attr/textAppearanceLarge"
          android:textSize="30sp"
          android:typeface="serif" /&gt;
     &lt;!--&lt;Button--&gt;
          &lt;!--android:id="@+id/equal1"--&gt;
          &lt;!--android:layout_width="match_parent"--&gt;
          &lt;!--android:layout_height="100dp"--&gt;
          &lt;!--android:text="="--&gt;
           &lt;!--/&gt;--&gt;
  
      &lt;Button
          android:id="@+id/equal2"
          android:layout_width="match_parent"
          android:layout_height="100dp"
          android:text="="
          android:layout_alignParentBottom="true"
           /&gt;
  
      &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_below="@id/txtScreen"
          android:orientation="vertical"
          android:layout_above="@id/equal2"&gt;
  
          &lt;LinearLayout
              android:layout_width="match_parent"
              android:layout_height="0dp"
              android:layout_weight="1"&gt;
  
              &lt;Button
                  android:id="@+id/onetwothree"
                  android:layout_width="0dp"
                  android:layout_height="match_parent"
                  android:layout_weight="1"
                  android:text="1/2/3"/&gt;
  
              &lt;Button
                  android:id="@+id/fourfivesix"
                  android:layout_width="0dp"
                  android:layout_height="match_parent"
                  android:layout_weight="1"
                  android:text="4/5/6"/&gt;
  
          &lt;/LinearLayout&gt;
  
          &lt;LinearLayout
              android:layout_width="match_parent"
              android:layout_height="0dp"
              android:layout_weight="1"&gt;
  
              &lt;Button
                  android:id="@+id/seveneightninezero"
                  android:layout_width="0dp"
                  android:layout_height="match_parent"
                  android:layout_weight="1"
                  android:text="7/8/9/0"/&gt;
  
              &lt;Button
                  android:id="@+id/operators"
                  android:layout_width="0dp"
                  android:layout_height="match_parent"
                  android:layout_weight="1"
                  android:text="+-*/"/&gt;
  
          &lt;/LinearLayout&gt;
  
      &lt;/LinearLayout&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Will it be possible for me to get the input of 1, 2 or 3 from my first button for example? So on 1 press you get 1, 2 press gives 2 etc.</p>
  
  <p>Any suggestions/ ideas on how I can move forward with this are greatly appreciated.</p>
  
  <p>Kind Regards,
  Ben</p>