title: How to store text from multiple buttons in one variable in android development?
body: <p>I want to store the text on a button in a variable.</p>
  
  <p>I refered <a href="https://stackoverflow.com/questions/9383512/how-to-store-button-text-of-buttons-in-a-variable-android-calculator-project">This</a> article but it defines for "One variable for one button".My app is going to have around 80-90 buttons. How can I store data from any of these buttons in a single variable and use that common variable for further operations?</p>
  
  <p>Example -</p>
  
  <p>I have buttons -  1,2,3,4,5,6,7,8,9</p>
  
  <p>How can I initialise them to a single button (the <code>btn = (Button) findViewById</code>... thing) in java and thus get their text in one single variable? Coz i cant define 90 buttons separately in java!!</p>
  
  <p>How can i do this?</p>
  
  <p>Here is the code of what ive done..(A completely supid or inefficient way)-</p>
  
  <p>What it basically does is - out of 12 buttons,whichever is pressed,concatinates it with a string.
  like if 1 is pressed the string will be 01 after that if 10 is pressed, the string will become 0110 and so on...</p>
  
  <pre><code>public class FEa extends Activity implements View.OnClickListener
  {
      Button b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12;
      TextView tvDisp;
      String acc;
  
      @Override
      protected void onCreate(Bundle savedInstanceState)
      {
          // TODO Auto-generated method stub
          super.onCreate(savedInstanceState);
          setContentView(R.layout.fea);
          initialise();
      }
  
      private void initialise()
      {
          b1 = (Button) findViewById (R.id.Btn1);
          b1.setOnClickListener(this);
          b2 = (Button) findViewById (R.id.Btn2);
          b2.setOnClickListener(this);
          b3 = (Button) findViewById (R.id.Btn3);
          b3.setOnClickListener(this);
          b4 = (Button) findViewById (R.id.Btn4);
          b4.setOnClickListener(this);
          b5 = (Button) findViewById (R.id.Btn5);
          b5.setOnClickListener(this);
          b6 = (Button) findViewById (R.id.Btn6);
          b6.setOnClickListener(this);
          b7 = (Button) findViewById (R.id.Btn7);
          b7.setOnClickListener(this);
          b8 = (Button) findViewById (R.id.Btn8);
          b8.setOnClickListener(this);
          b9 = (Button) findViewById (R.id.Btn9);
          b9.setOnClickListener(this);
          b10 = (Button) findViewById (R.id.Btn10);
          b10.setOnClickListener(this);
          b11 = (Button) findViewById (R.id.Btn11);
          b11.setOnClickListener(this);
          b12 = (Button) findViewById (R.id.Btn12);
          b12.setOnClickListener(this);
          tvDisp=(TextView) findViewById (R.id.TxtViewDisplay);
  
      }
  
      @Override
      public void onClick(View v)
      {
          // TODO Auto-generated method stub
  
          switch(v.getId())
          {
          case R.id.Btn1:
  
              if(acc == null)
              {
                  acc = "01";
                  tvDisp.setText("String Is:" + acc);
              }
              else
              {
                  acc=acc + "0"+1;
                  tvDisp.setText("String Is:" + acc);
              }
  
              break;
          case R.id.Btn2:
  
              if(acc == null)
              {
                  acc = "02";
                  tvDisp.setText("String Is:" + acc);     
              }
              else
              {
                  acc = acc + "0"+2;
                  tvDisp.setText("String Is:" + acc);
              }
              break;
          case R.id.Btn3:
  
              if(acc == null)
              {
                  acc = "03";
                  tvDisp.setText("String Is:" + acc);     
              }
              else
              {
                  acc = acc + "0"+3;
                  tvDisp.setText("String Is:" + acc);
              }
              break;
          case R.id.Btn4:
  
              if(acc == null)
              {
                  acc = "04";
                  tvDisp.setText("String Is:" + acc);     
              }
              else
              {
                  acc = acc + "0"+4;
                  tvDisp.setText("String Is:" + acc);
              }
              break;
          case R.id.Btn5:
  
              if(acc == null)
              {
                  acc = "05";
                  tvDisp.setText("String Is:" + acc);     
              }
              else
              {
                  acc = acc + "0"+5;
                  tvDisp.setText("String Is:" + acc);
              }
              break;
          case R.id.Btn6:
  
              if(acc == null)
              {
                  acc = "06";
                  tvDisp.setText("String Is:" + acc);     
              }
              else
              {
                  acc = acc + "0"+6;
                  tvDisp.setText("String Is:" + acc);
              }
              break;
          case R.id.Btn7:
  
              if(acc == null)
              {
                  acc = "07";
                  tvDisp.setText("String Is:" + acc);     
              }
              else
              {
                  acc = acc + "0"+7;
                  tvDisp.setText("String Is:" + acc);
              }
              break;
          case R.id.Btn8:
  
              if(acc == null)
              {
                  acc = "08";
                  tvDisp.setText("String Is:" + acc);     
              }
              else
              {
                  acc = acc + "0"+8;
                  tvDisp.setText("String Is:" + acc);
              }
              break;
          case R.id.Btn9:
  
              if(acc == null)
              {
                  acc = "09";
                  tvDisp.setText("String Is:" + acc);     
              }
              else
              {
                  acc = acc + "0" +9;
                  tvDisp.setText("String Is:" + acc);
              }
              break;
          case R.id.Btn10:
  
              if(acc == null)
              {
                  acc = "10";
                  tvDisp.setText("String Is:" + acc);     
              }
              else
              {
                  acc = acc + 10;
                  tvDisp.setText("String Is:" + acc);
              }
              break;
          case R.id.Btn11:
  
              if(acc == null)
              {
                  acc = "11";
                  tvDisp.setText("String Is:" + acc);     
              }
              else
              {
                  acc = acc + 11;
                  tvDisp.setText("String Is:" + acc);
              }
              break;
          case R.id.Btn12:
  
              if(acc == null)
              {
                  acc = "12";
                  tvDisp.setText("String Is:" + acc);     
              }
              else
              {
                  acc = acc + 12;
                  tvDisp.setText("String Is:" + acc);
              }
              break;
          }
      }
  }
  </code></pre>