title: Android: How to use setOnClickListener/onClick for 20 different buttons?
body: <p>In my Android App there is a activity with 20 buttons in it. Each button have to go to another activity/page.
  I've tried several ways but i can't use a intent so much times.</p>
  
  <p>Option 1:</p>
  
  <pre><code>public void onClick(View v) {
  
  switch(v.getId()){
  
  case R.id.ivNB: 
     Intent intent = new Intent(this, NoordBrabant.class);
     this.startActivity(intent);
     break;
  
  case R.id.ivZH1: 
     Intent intent = new Intent(this, ZuidHolland.class);
     this.startActivity(intent);
     break;
  
  /**** End so 20 more ****/
  }
  </code></pre>
  
  <p>In the second case, the intent is not good, did i can't use more intents in 1 switch?</p>
  
  <p>Option 2:</p>
  
  <pre><code>ivNB.setOnClickListener(new View.OnClickListener() {
  
          public void onClick(View v) {
              // TODO Auto-generated method stub
              Intent i = new Intent(getApplicationContext(), NoordBrabant.class);
              startActivity(i);
          }
  
      });
      ivZeeland.setOnClickListener(new View.OnClickListener() {
  
          public void onClick(View v) {
              // TODO Auto-generated method stub
              Intent i = new Intent(getApplicationContext(), Zeeland.class);
              startActivity(i);
          }
  
      });
  /**** End so 20 more ****/
  </code></pre>
  
  <p>This way work with 5 of maby 10 the same, but with 20 the App crashes.</p>
  
  <p>Option 3:</p>
  
  <pre><code>public void onClick(View v) {
          if (v == ivGelderland){
              Intent intent = new Intent(this, Gelderland.class);
              this.startActivity(intent);
          }
          else if (v == ivNB) {
              Intent intent = new Intent(this, NoordBrabant.class);
              this.startActivity(intent);
          }
          else if (v == ivLimburg) {
              Intent intent = new Intent(this, Limburg.class);
              this.startActivity(intent);
          }
  /**** End so 20 more ****/
  </code></pre>
  
  <p>This way doesn't work at all, did i do something wrong here??</p>
  
  <p>Please can someone help me, i'm struggling a couple of days with it now!</p>
  
  <p>Thank you!</p>