title: Android - Dynamically set intent Extras
body: <p>I'm trying to pass an ID to my new activity on creation.</p>
  
  <p>The obvious solution seems to be to use "Intent.putExtra(name, value);". 
  But as the intent is only created on click, all of my buttons have the same Intent extras (useally null).</p>
  
  <p>Is there any way i can initialize these from a loop?</p>
  
  <pre><code>for ( int i = 0; i&lt; IDList.size() ; i++) 
      {
          //Get Information from ID
  
          btnDetails.setOnClickListener(new OnClickListener() 
          {
              public void onClick(View v)
              {
                  Intent intent = new Intent(getApplicationContext(),DetailActivity.class);
                  intent.putExtra("", IDList.get(i));
                  startActivity(intent);
              }
          });
  
          //Add To Screen
      }
  </code></pre>
  
  <p>In the code snippit IDList.get(i) is out of scope and a new Final Int isn't checked until the button is clicked, also going out of scope.</p>
  
  <p>Is there any other was i can send the variable on click?</p>