title: Android Button setOnClickListener Design
body: <p>I am building an Android Application. I've noticed that I am creating many repetitions of code similar to this in each of my classes:</p>
  
  <pre><code>Button buttonX = (Button)findViewById(R.id.buttonXName);
  // Register the onClick listener with the implementation above
  buttonX.setOnClickListener(new OnClickListener() {
      public void onClick(View v)
      {
          //DO SOMETHING! {RUN SOME FUNCTION ... DO CHECKS... ETC}
      } 
  });
  </code></pre>
  
  <p>I now have fifteen buttons and this is making my code ugly. Does anyone have a class or some examples on how I can turn all these codes into something more efficient, so I can:</p>
  
  <ol>
  <li>Create the button object <code>{Button buttonX (Button)findViewById(R.id.buttonXName);}</code></li>
  <li>Set the listener <code>{buttonX.setOnClickListener(new OnClickListener()}</code></li>
  <li>Determine if it was clicked <code>{public void onClick(View v)}</code></li>
  <li>Then run specific code for each button?</li>
  </ol>
  
  <p>If anyone knows anything, I'd appreciate it.</p>