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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:27:59+00:00 2026-06-08T10:27:59+00:00

It was tricky to write a title for this. What I currently do, is

  • 0

It was tricky to write a title for this. What I currently do, is to reuse one Fragment class to create a multitude of ListFragments in a ViewPager.
The layout of the ListFragments are all the same so having just one layout and one Fragment as a base seems like a sound choice.
However, I’d like to be able to access each Fragment’s views, in order to set some per-Fragment values, such as a title, a name and whatnot. I have an issue with this and it’s the fact that whenever I try to access a TextView by overriding a Fragment’s onViewCreated-method, it seems to me that the only Fragment getting updated is the first one in the chain.

Now, what I do to instantiate and connect the Fragments is this:

private void initPager() {
    mFragments = new Vector<Fragment>();
    int[] listIds = 3;
    for(int i = 0; i < listIds.length; i++) {
        Fragment fragment = new ListsFragment(listIds[i]);
        mFragments.add(fragment);
    }

    FragmentManager fragmentManager = getSupportFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    for(int i = 0; i < mFragments.size(); i++) {
        fragmentTransaction.add(R.id.viewpager, mFragments.get(i));
    }
    fragmentTransaction.commit();

    mPagerAdapter = new ListsPagerAdapter(fragmentManager, mFragments);
    mPager = (ViewPager) super.findViewById(R.id.viewpager);
    mPager.setAdapter(mPagerAdapter);
}

The Fragment onViewCreated() code is this:

    @Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    TextView textListTitle = (TextView) getActivity().findViewById(R.id.text_list_title);
            String title = "test";
    textListTitle.setText(listTitle);
}

When looking at logs I see that each Fragment is instantiated separatly, going through the lifecycle of each in succession. However, the only Fragment getting the “test”-string is the first one.

What am I missing?

  • 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-08T10:28:01+00:00Added an answer on June 8, 2026 at 10:28 am

    You should be instantiating your Fragments in a FragmentPagerAdapter of some sort.

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

Sidebar

Related Questions

This one is a little tricky to explain. I would like to create a
So I've got this tricky (at least for me) script to write/modify. You can
I've got a slightly tricky problem to solve; imagine this: One of my applications
Ok this is a tricky one. I have a list of Sets. I would
This one is tricky to me: I have four groups of 8 LEDs. A
This is going to be a little tricky to explain. I'm trying to write
That one is a tricky one I believe. I would like to merge two
This is a slightly tricky question. I am using NSDateFormatter on the iPhone but
I'm having a tricky time in thrashing out how best to approach this particular
I am trying to write a query that grabs information from one database and

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.