title: CheckBox[] with onClickListener[]?
body: <p><strong>EDIT: this question is mostly closed and the only problems i have with this code are discussed <a href="https://stackoverflow.com/q/6230466/708685">here</a></strong></p>
  
  <p>For part of my app, I have a page of items that are represented as checkboxes, each with a associated boolean that eventually get collected and stored as a string as follows:</p>
  
  <pre><code>final CheckBox gas_oil = (CheckBox) findViewById(R.id.gas_oil);
  gas_oil.setOnClickListener(new OnClickListener()
  {
  public void onClick(View v)
      {
      if (gas_oil.isChecked())
          {
          impacts.append(getString(R.string.gas_oil) + " | ");
          anythingchecked = true;
          }
      }
  });
  </code></pre>
  
  <p>this is extremely tedious and did not seem to be a very efficent way to do this since i have 9 or 10 items that users can check or not. also this method means that if they click and unclick something, that item is still in the <code>StringBuilder impacts</code> and that if they click it again then it is in there twice.</p>
  
  <p>My solution was to have everything in arrays:</p>
  
  <pre><code>  String[] impactsn = getResources().getStringArray(R.array.impacts);
    final boolean[] impactsb = new boolean[impactsn.length];
    final CheckBox[] impactsc = new CheckBox[impactsn.length];
    View[] impactsv = new View[]{findViewById(R.id.gas_oil),findViewById(R.id.ghost_fishing),findViewById(R.id.marsh_damage),findViewById(R.id.nav_haz),findViewById(R.id.shell_damage),findViewById(R.id.waste_pollution),findViewById(R.id.wild_entang),findViewById(R.id.other)};
  
    for (int i = 0; i &lt; impactsn.length; i++)
      {
      impactsc[i] = (CheckBox) impactsv[i];
      impactsc[i].setOnClickListener(new OnClickListener()
              {   
              @Override
              public void onClick(View v)
                  {
                  if (impactsc[i].isChecked())
                      impactsb[i] = true;
                  else
                      impactsb[i] = false;
                  }
              });
      }
  </code></pre>
  
  <p>unfortunately doing this causes the problem that (as far as i understand it) things within an <code>OnClickListener</code> have to be final. With the code as written, <code>i</code> can never be final, so I'm sort of at a standstill.</p>
  
  <p>Should/can I have an array of <code>OnClickListeners</code> as well? Should I be calling to a method outside of the code I have here?</p>
  
  <p>Also, below is the getter i was planning on using, I think that part will work just fine:</p>
  
  <pre><code>String getImpacts ()
      {
              String[] impactsn = getResources().getStringArray(R.array.impacts);
      StringBuilder impactss = new StringBuilder();
      for (int i = 0; i &lt; impactsn.length; i ++)
          {
          if (impactsb[i])
                      impactss.append(impactsn[i] + " | ");
          }
      return String.valueOf(impactss);
      }
  </code></pre>
  
  <p><strong>EDIT: this is the version of code im running with now:</strong></p>
  
  <p>package com.citsci.mardeb;</p>
  
  <p>import android.app.Activity;
  import android.content.res.Resources;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.CheckBox;
  import android.widget.EditText;</p>
  
  <p>public class Impacts extends Activity implements View.OnClickListener
  {
      int length = 7;
      boolean[] impactsb = new boolean[] {false, false, false, false, false, false, false, false};
      EditText    view;</p>
  
  <pre><code>public void onCreate (Bundle savedInstanceState)
  {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.impacts);
  </code></pre>
  
  <p>//      for (int i = 0; i &lt; length; i++)
  //          impactsb[i] = false;</p>
  
  <pre><code>  View[] impactsv = new View[]
       {
      findViewById(R.id.gas_oil),
          findViewById(R.id.ghost_fishing),
          findViewById(R.id.marsh_damage),
          findViewById(R.id.nav_haz),
          findViewById(R.id.shell_damage),
          findViewById(R.id.waste_pollution),
          findViewById(R.id.wild_entang),
          findViewById(R.id.other)
          };
  
    CheckBox[] impactsc = new CheckBox[length];
  
    for (int i = 0; i &lt; length; i++)
       {
       impactsc[i] = (CheckBox) impactsv[i];
       impactsc[i].setOnClickListener(this);
       }
  
  }// end of onCreate
  
  @Override
  public void onClick(View v)
      {
    switch (v.getId()) {
       case (R.id.gas_oil):
          impactsb[0] =! impactsb[0];
          break;
       case (R.id.ghost_fishing):
          impactsb[1] =! impactsb[1];
          break;
       case (R.id.marsh_damage):
          impactsb[2] =! impactsb[2];
          break;
       case (R.id.nav_haz):
          impactsb[3] =! impactsb[3];
          break;
       case (R.id.shell_damage):
          impactsb[4] =! impactsb[4];
          break;
       case (R.id.waste_pollution):
          impactsb[5] =! impactsb[5];
          break;
       case (R.id.wild_entang):
          impactsb[6] =! impactsb[6];
          break;
       case (R.id.other):
          impactsb[7] =! impactsb[7];
          }
      }
  
  String getImpacts ()
      {
      String[] impactsn = new String[length];
      Resources myResources = getResources();
      impactsn = myResources.getStringArray(R.array.impacts);
    StringBuilder impactss = new StringBuilder();
      for (int i = 0; i &lt; length; i ++)
          {
          if (impactsb[i])
              impactss.append(impactsn[i] + " | ");
          }
      if (String.valueOf(impactss) != "")
          impactss.insert(0, "Impacts: ");
      return String.valueOf(impactss);
      }
  }// end of Impacts.class
  </code></pre>