title: Dynamically set id of a view
body: <p>I have to dynamically create 4 <strong>Buttons</strong> and I have to generate dynamically their id, something like:</p>
  
  <pre><code>  for(int i = 1; i &lt;= 4; i++){
      Button button = new Button(activity);
  
      // i need something here to turn this string into an int;    
      button.setId("button" + i) 
    }
  </code></pre>
  
  <p>I know how to dynamically get the id of an existing view:</p>
  
  <pre><code>getResources().getIdentifier("button2", "button", getPackageName())
  </code></pre>
  
  <p>What I don't know, is how to generate the id dynamically.</p>
  
  <p>I looked on the internet but I didn't find in anything.</p>
  
  <p>I need something like:</p>
  
  <pre><code>int id = getResources().setIdentifier("button2", "button", getPackageName());
  button.setid(id);
  </code></pre>
  
  <p>Thank you in advance.</p>