title: How to implement an array of TextView objects in a for loop?
body: <p>I want to minimise the code by using for loop with TextView objects a,b,c,d,e as elements of an array. Both for findViewById and setOnClickListener implementations. Any actionable walkthrough for this particular coding is really appreciated!^__^</p>
  
  <ul>
  <li><p>The following is how I usually do the TextView implementations. But I
  am tired of writing so many lines needlessly.</p>
  
  <p>TextView a,b,c,d,e;</p>
  
  <pre><code>    a=(TextView)findViewById(R.id.A);
      b=(TextView)findViewById(R.id.B);
      c=(TextView)findViewById(R.id.C);
      d=(TextView)findViewById(R.id.D);
      e=(TextView)findViewById(R.id.E);
  
      a.setOnClickListener(this);
      b.setOnClickListener(this);
      c.setOnClickListener(this);
      d.setOnClickListener(this);
      e.setOnClickListener(this);
  </code></pre></li>
  <li><p>My question is if I can use a loop to set all the already initialized
  TextView objects to call setOnClickListener() without any trouble as
  shown below:</p>
  
  <pre><code>TextView a,b,c,d,e;
  
  a=(TextView)findViewById(R.id.A);
  b=(TextView)findViewById(R.id.B);
  c=(TextView)findViewById(R.id.C);
  d=(TextView)findViewById(R.id.D);
  e=(TextView)findViewById(R.id.E);
  </code></pre>
  
  <p>TextView[] textViews = {a, b, c, d, e};</p>
  
  <pre><code>for (int count = 0; count &lt; textViews.length; count++) {
      textViews[count].setOnClickListener(this);
  }
  </code></pre></li>
  </ul>
  
  <p>**</p>
  
  <ul>
  <li><p>All I want to know is how to initialize the TextView objects
  a,b,c,d,e in the same way, I showed to setOnClickListener for them? Something like this,</p>
  
  <pre><code>TextView[] textViews = {a, b, c, d, e};
  
  int[] textViewIds = {R.id.a, R.id.b, R.id.c, R.id.d, R.id.e};
  
  for (int count = 0; count &lt; textViews.length; count++) {
      textViews[count] = (TextView)findViewById(textViewIds[count]);
  }
  </code></pre></li>
  </ul>
  
  <p>**</p>