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 8191179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:51:42+00:00 2026-06-07T03:51:42+00:00

I have a ViewPager that has one ImageView per view. I need to setup

  • 0

I have a ViewPager that has one ImageView per view. I need to setup an OnTouchListener for the currentItem in the view. I have the following code but keep getting NULL when I try and setup the listener. Below is my code. How can I get a valid reference to my current items ImageView???

private class CalendarPagerAdapter extends PagerAdapter {

        public int getCount() {
            return NUM_VIEW;
        }

        public Object instantiateItem(View collection, int position) {

            View view=null;

            LayoutInflater inflater = (LayoutInflater) collection.getContext()
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

            int resId = 0;
            switch (position) {
            case 0:
                resId = R.layout.cal_july;
                view = inflater.inflate(resId, null);
                calendar = (ImageView) findViewById(R.id.imageView1);
                                // IT IS ALWAYS NULL HERE
                if(calendar == null) {
                    System.out.println("its null!!!!!!");
                } else {
                    System.out.println("its NOT NULL!!!!!");
                }
                // Breaks here, obviously!!!
                calendar.setOnTouchListener(getOnTouchListener());
                break;
            case 1:
                resId = R.layout.cal_august;
                view = inflater.inflate(resId, null);
                calendar = (ImageView) findViewById(R.id.imageView1);
                calendar.setOnTouchListener(getOnTouchListener());
                break;              
            case 2:
                resId = R.layout.cal_september;
                break;
            case 3:
                resId = R.layout.cal_october;
                break;
            case 4:
                resId = R.layout.cal_november;
                break;

            }

            ((ViewPager) collection).addView(view, 0);

            return view;
        }
  • 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-07T03:51:43+00:00Added an answer on June 7, 2026 at 3:51 am

    When you call:

    view = inflater.inflate(resId, null);
    calendar = (ImageView) findViewById(R.id.imageView1);
    

    it looks for the ImageView with the ID R.id.imageView1 in your Activity’s contentView (ie: the layout that you originally set in your onCreate(). I assume that isn’t what you want.

    You probably want to find the view in the view you just inflated. Try this:

    view = inflater.inflate(resId, null);
    calendar = (ImageView) view.findViewById(R.id.imageView1);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a view, that is of Inherits from System.Web.Mvc.ViewPage<P> . Type P has
I have a layout that has a ViewPager inside of a custom ScrollView and
I have a ViewPager with multiple fragments. In one Fragment I play audio. When
I have a ViewPager with 4 views. View #3 needs to respond to some
I have implemented HorizontalListView inside ViewPager . ViewPager works fine but a child of
I have this structure: Activity A has a ViewPager. The pages of a ViewPager
I have the following structure in my app: FragmentActivity with ViewPager holding multiple fragments
I have a custom sliding drawer that basically has very same traits as a
I am building an mvc app for reporting. I have a page that has
I am getting an odd error from an MVC3 webforms view that has stumped

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.