Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8173145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:02:03+00:00 2026-06-06T22:02:03+00:00

I have this loop method to display a ViewPager and I set an OnClickListener

  • 0

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

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

for(i = 0; i < 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);



            }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T22:02:05+00:00Added an answer on June 6, 2026 at 10:02 pm

    Try to set as the tag for the ImageView the string footage_video_url[i] and then retrieve it in the OnClickListener. This way you’re sure the correct String will be put in the extras:

    imageView.setTag(footage_video_url[i]);
    imageView.setOnClickListener(new View.OnClickListener() {
         public void onClick(View v) {
              String theUrl = (String) v.getTag(); // I hope it's a String
              Intent listIntent = new Intent(getApplicationContext(),
                                        VideoPlayer.class);
              listIntent.putExtra("video_url", theUrl);
              System.out.println("Video Number "+i+" : "+ theUrl);
              startActivity(listIntent);
         }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this loop for (it= someCollection.iterator; it.hasNext(); ) { //some code here }
So I do have this loop, but it stops when it come to function
In my code, I have this loop, which brings up various 2-hour time blocks.
I have this block of code inside a loop: var points = [new google.maps.LatLng(lat1,
I have this PHP code in a loop for every post on the admin
I have this class in which I run a for loop 10 times. This
I have this code that makes a string and then echos the loop out
Possible Duplicate: php loop through associative arrays i have this piece of code which
I have created this function to check abecedarian with while loop (A word is
I have this action method: [HttpPost] public ActionResult GetNextImage(int m_id) { ... return Json(new{...});

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.