title: How to use looping construct to iterate some view ids?
body: <p>Instead of doing the following,</p>
  
  <pre><code>ButtonHandler bh = new ButtonHandler();
  findViewById(R.id.button1).setOnClickListener(bh);
  findViewById(R.id.button2).setOnClickListener(bh);
  findViewById(R.id.button3).setOnClickListener(bh);
  </code></pre>
  
  <p>that seems too verbose, I attempted to rewrite them as follows but fails.</p>
  
  <pre><code>ButtonHandler bh = new ButtonHandler();
  for (int id : int[]{R.id.button1, R.id.button2, R.id.button3}) {
      findViewById(id).setOnClickListener(bh);
  }
  </code></pre>
  
  <h1>Question</h1>
  
  <p>How to use looping construct to iterate some view ids as mentioned above? </p>
  
  <p><a href="https://i.stack.imgur.com/VMF88.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VMF88.png" alt="enter image description here"></a></p>