title: How to deal with repeated code for many buttons in an efficient way
body: <p>I have  about 20 buttons b1, b2,b3,...bn, with almost the same content, I don't want to repeat the same code, what I want  is: an efficient code in order not to repeat the same code, here's my code:</p>
  
  <pre><code>b1.setOnClickListener(new OnClickListener() {
          @Override
          public void onClick(View v) {
              //Changes per button
              act1 = titl1;
              act2= tex1;
              act3=pic1;
  
              //Common code for all buttons
              Bundle b1 = new Bundle();
              Bundle b2 = new Bundle();
              Bundle b3 = new Bundle();
              b1.putString("somekey1", act1);
              b2.putString("somekey2", act2);
              b3.putString("somekey2", act3);
              Intent i = new Intent(getApplicationContext(), Content1.class);
              i.putExtras(b1);
              i.putExtras(b2);
              i.putExtras(b3);
              startActivity(i);
              overridePendingTransition(R.anim.pushinhorizontal,
                      R.anim.pushouthorizontal);
          }
      });
  
      b2.setOnClickListener(new OnClickListener() {
          @Override
          public void onClick(View v) {
              //Changes per button
              act1 = titl2;
              act2= tex2;
              act3=pic2;
  
              //Common code for all buttons
              Bundle b1 = new Bundle();
              Bundle b2 = new Bundle();
              Bundle b3 = new Bundle();
              b1.putString("somekey1", act1);
              b2.putString("somekey2", act2);
              b3.putString("somekey2", act3);
              Intent i = new Intent(getApplicationContext(), Content1.class);
              i.putExtras(b1);
              i.putExtras(b2);
              i.putExtras(b3);
              startActivity(i);
              overridePendingTransition(R.anim.pushinhorizontal,
                      R.anim.pushouthorizontal);
          }
      });
  </code></pre>