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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:49:57+00:00 2026-06-04T11:49:57+00:00

Background I’m writing an app that uses the ViewPager and that’s working nicely. I

  • 0

Background

I’m writing an app that uses the ViewPager and that’s working nicely. I need to be able to target one of the layouts (xml file) and update the textviews and imageviews on it. I’ve tried inflating the view and targeting with “v.findViewById”, which seems to be the solution from my research but maybe I’m putting it in the correct place and need it explained better to me.

My Code (without trying to target)

private ImageView circle;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    circle = (ImageView) findViewById(R.id.circles);

    MyPagerAdapter adapter = new MyPagerAdapter();
    ViewPager myPager = (ViewPager) findViewById(R.id.myViewPager);
    myPager.setAdapter(adapter);
    myPager.setCurrentItem(1);
    myPager.setOnPageChangeListener(new MyPageChangeListener()); 
}

private int focusedPage = 0;
private class MyPageChangeListener extends ViewPager.SimpleOnPageChangeListener {
    @Override
    public void onPageSelected(int position) {
        focusedPage = position;

        switch (focusedPage) {
            case 0: circle.setImageResource(R.drawable.circles1); break;
            case 1: circle.setImageResource(R.drawable.circles2); break;
            case 2: circle.setImageResource(R.drawable.circles3); break;
            case 3: circle.setImageResource(R.drawable.circles4); break;
        }
    }
}

private class MyPagerAdapter extends PagerAdapter {

    public int getCount() {
        return 4;
    }

    public Object instantiateItem(View collection, int position) {

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

        int resId = 0;
        switch (position) {
            case 0:
                resId = R.layout.zip;
                break;
            case 1:
                resId = R.layout.forecast;
                break;
            case 2:
                resId = R.layout.settings;
                break;
            case 3:
                resId = R.layout.about;
                break;
        }

        View view = inflater.inflate(resId, null);

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

        return view;
    }

    @Override
    public void destroyItem(View arg0, int arg1, Object arg2) {
        ((ViewPager) arg0).removeView((View) arg2);
    }

    @Override
    public boolean isViewFromObject(View arg0, Object arg1) {
        return arg0 == ((View) arg1);

    }

    @Override
    public Parcelable saveState() {
        return null;
    }
}

FYI: the ImageView “cicle” is an image of 4 circles at the bottom of the screen that gets updated on page change to show what screen you’re on. working fine, just wanted to explain.

GOAL

Update a textview named “city” on the layout named “forecast”.

Thanks in advance for any help! After this little hurdle, it should be easy sailing.

  • 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-04T11:49:59+00:00Added an answer on June 4, 2026 at 11:49 am

    Well I don’t garantee that this works but I had a similar problem with ViewPager using compatibility pack that I solved using this:

    In your view at the instatiateItem function do a setTag with your resId:

    view.setTag(resId);
    

    Then when you need to change your “city” do:

    View baseLayout = myPager.findViewWithTag(R.layout.forecast);
    TextView city = (TextView) baseLayout.findViewById(R.id.city_id);
    

    Where R.id.city_id is the id of your TextView.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background I am working with a monad built of a stack of transformers one
Background This is only my second PyQt4 project. Developing a Windows app that has
Background My project is urgent and requires that I iterate a large XML file
Background: I am using Eclipse to develop an Android app. I have an xml
Background: I have a winform application written in VB.NET that uses a WebService to
Background: I have a winforms app written in C# that converts xlsx files to
Background: I have a winForm app that registers a user in the database based
Background: I have a winForm app that registers a user in the database based
Background: What I need to accomplish is to remove any records in a collection
Background: We're building an application that allows our customers to supply data in a

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.