a Looped OnClickListener always gets the wrong index array
<p>I have this loop method to display a <code>ViewPager</code> and I set an <code>OnClickListener</code> for each Image on the <code>ViewPager</code>. So when the image is clicked, the user will be brought to a VideoPlayer class. but I don't know why, the <code>footage_video_url[i]</code> on <code>putExtra()</code> of the click listener always reads that the <code>i</code> on the extra is the maximum length. So the <code>i</code> always exceeds the maximum array length and that makes the app crash.</p>

<p>What I was expecting is, if for example the displayed image is <code>footage_thumbnail_url[1]</code>, the String which is put on extra is <code>footage_video_url[1]</code> respectively, and so on.
Does anybody know where I go wrong?    </p>

<pre><code>for(i = 0; i &lt; length; i++){
                final String[] video_url = footage_video_url;
                final String[] thumbnail_url = footage_thumbnail_url;

                //System.out.println("FOOTAGE VIDEO DETAILS " +i+ ": " +video_url[i]);

                FrameLayout content = new FrameLayout(this);
                FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
                        (int) size, (int) size);
                params.gravity = Gravity.CENTER;

                ImageView imageView = new ImageView(this);
                ImageLoader loader = new ImageLoader(this);

                // Image from URL
                if (footage_thumbnail_url[i].contains("http"))
                    loader.downloadPicture(imageView, footage_thumbnail_url,i);
                else {
                    // Image From SDCard
                    File imgFile = new File(thumbnail_url[i]);
                    Bitmap bitmapImage = loader.decodeFile(imgFile);
                    Drawable drawableImage = new BitmapDrawable(bitmapImage);
                    imageView.setBackgroundDrawable(drawableImage);

                    imageView.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View v) {
                            Intent listIntent = new Intent(getApplicationContext(),
                                    VideoPlayer.class);
                            listIntent.putExtra("video_url", footage_video_url[i]);
                            System.out.println("Video Number "+i+" : "+ footage_video_url[i]);
                            startActivity(listIntent);
                        }
                    });
                }


                content.addView(imageView);

                View overlay = new View(this);
                overlay.setBackgroundResource(R.drawable.btn_play);
                params.gravity = Gravity.CENTER;
                overlay.setLayoutParams(params);
                overlay.invalidate();

                content.addView(overlay);
                pagerViews.add(content);



            }
</code></pre>
