title: Getting the value of clicked buttons and append them
body: <p>I'm newbie in android development and going to create simple <strong>drag'n'Drop</strong> calculator.
  My goal is to make buttons from <strong>0 to 9</strong> and create numbers by clicking them.</p>
  
  <p>For example:</p>
  
  <p><strong>0 1 2 3 4 5 6 7 8 9</strong></p>
  
  <p>and by clicking them create number <strong>245</strong>, then drag this number, for example, into the <strong>sum mark +</strong>, then repeat second number and automatically retrieve results.</p>
  
  <p>First, I'll show my code now...</p>
  
  <p><strong>MainActivity.java</strong></p>
  
  <pre><code>package com.coreprojects.calculator;
  
  import android.os.Bundle;
  import android.view.View;
  import android.widget.Button;
  import android.widget.TextView;
  import android.app.Activity;
  
  public class MainActivity extends Activity {
  
      TextView calc_btn;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
      }
  
      // This method comes from XML button = buttonClick
      public void buttonClick(View v) {
  
          // Textarea where numbers will be shown
          TextView TV = (TextView) findViewById(R.id.calc_cache_1);
  
          // Get the ID of buttons
          Button calc_btn_1 = (Button) findViewById(R.id.button1);
          Button calc_btn_2 = (Button) findViewById(R.id.button2);
  
          // INT type numbers convert to string, because of [setText]
          String buttonText_1 = calc_btn_1.getText().toString();
          String buttonText_2 = calc_btn_2.getText().toString();
  
          // Result as text
          TV.setText(buttonText_1); // first number is not shown
          TV.setText(buttonText_2); // second number
  
  
          // alert
          /**
          String pressed = "Operation Done";
          new AlertDialog.Builder(this).setTitle("result").setMessage(pressed)
                  .setNeutralButton("Done", null).show();
          */
      }
  
  }
  </code></pre>
  
  <p><strong>activity_main.xml</strong></p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context=".MainActivity" &gt;
  
      &lt;TextView
          android:id="@+id/calc_cache_1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_centerHorizontal="true"
          android:layout_centerVertical="true"
          android:text="@string/main_text" /&gt;
  
      &lt;Button
          android:id="@+id/button1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentBottom="true"
          android:layout_alignParentLeft="true"
          android:clickable="true"
          android:onClick="buttonClick"
          android:text="@string/button_1" /&gt;
  
      &lt;Button
          android:id="@+id/button2"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentBottom="true"
          android:layout_alignParentLeft="true"
          android:layout_marginLeft="64dp"
          android:clickable="true"
          android:onClick="buttonClick"
          android:text="@string/button_2" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p><strong>strings.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;resources&gt;
  
      &lt;string name="app_name"&gt;Calculator&lt;/string&gt;
      &lt;string name="main_text"&gt;&lt;/string&gt;
      &lt;string name="menu_settings"&gt;Settings&lt;/string&gt;
      &lt;string name="button_1"&gt;1&lt;/string&gt;
      &lt;string name="button_2"&gt;2&lt;/string&gt;
  
  &lt;/resources&gt;
  </code></pre>
  
  <p>Now problem...</p>
  
  <p>When i click on buttons, any time result shows number 2, because i think </p>
  
  <blockquote>
    <p>TV.setText(buttonText_2) is second command and first one is not read any more.</p>
  </blockquote>
  
  <p>I tried to write together, like TV.setText(buttonText_1 + buttonText_2), but now it results <strong>12</strong>, even if i click any single button...</p>
  
  <p>so how can I append numbers by clicking them? and also, if u see here, i have clickable button in XML, and get ID of pressed button, but i want it to be more dynamic.</p>
  
  <p>For example: when i press button, don't get the ID of it, but simply identify the button ID and get value. i can show u simple analog in jQuery:</p>
  
  <pre><code>$(".button_class_not_ID").click(
      var elementValue = $(this).html();
      or
      var elementValue = $(this).attr("id");
      console.log(elementValue);
  );
  </code></pre>