title: Is there a fast way to initialize multiple buttons numbered 1-10 using for loop? (Android Application)
body: <p>I have an init method that finds each button using findViewById(R.id.pin1) and then sets an onclick method that has the method write to a bluetooth output stream.</p>
  
  <pre><code>    Button myButton = (Button) findViewById(R.id.pin1);
      myButton.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View v) {
              // TODO Auto-generated method stub
              String msg = "1".toString();
              try {
                  mmOutStream.write(msg.getBytes());
              } catch (IOException e) {
                  error();
              }
          }
      });
  </code></pre>
  
  <p>Very quite literally, all I change is the 1 to 2 and so on. So the next code segment is:</p>
  
  <pre><code>    Button myButton = (Button) findViewById(R.id.pin2);
      myButton.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View v) {
              // TODO Auto-generated method stub
              String msg = "2".toString();
              try {
                  mmOutStream.write(msg.getBytes());
              } catch (IOException e) {
                  error();
              }
          }
      });
  </code></pre>
  
  <p>I tried a few things like making a string like string pinButton = "pin" + i.toString() and then R.id.pinButton but it doesn't work. (That is, the i is in a forloop that I surrounded the code with)</p>