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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:26:32+00:00 2026-06-11T09:26:32+00:00

I have a ViewPager within a Fragment in my application. Within the ViewPager I

  • 0

I have a ViewPager within a Fragment in my application. Within the ViewPager I have 6 list views which pull their data from a central data source (a Schedule, which each list view then pulls Lists of days from). Now I’m trying to update this schedule object by changing the schedule that is stored in my PagerAdapter class, and then updating the ArrayAdapter that serves as the adapter to all the list views. When one list view is switched to, a new array adapter is created with the correct data.

Unfortunately this doesn’t work at all. I cannot see any data at any point in the application lifecycle. So I’m assuming I’m doing something fundamentally wrong in connecting my data to my ViewPager…

I’ve been all over the net, read up on all of the fragment stuff, a LOT of the view pager stuff…
Does anyone know the correct way to do this?

Heres the code for my DayAdapter (ViewPagerADapter)

public final class DayAdapter extends PagerAdapter {

    //~Data Fields----------------------------------------//
    /**
     * The list adapter that the current list is being handed to.
     */
    private Schedule schedule;
    /**
     * The current index of the day that is to be displayed.
     */
    private int currentIndex;
    /**
     * ArrayAdpter to be used to connect data to all of the list views.
     */
    private ArrayAdapter<Course> adapter;

    //~Constructors---------------------------------------//
    /**
     * Constructor for the DayAdapter implementation of PagerAdapter. Takes in a
     * Schedule object which is to be the data backing of the views displayed.
     * 
     * @param theSChedule the Schedule object that is the backing for the ListViews.
     */
    public DayAdapter(Schedule theSchedule) {

        schedule = theSchedule;
        currentIndex = schedule.getTodayIndex();
    }

    //~Methods--------------------------------------------//
    public void setSchedule(Schedule theSchedule) {

        schedule = theSchedule;

        adapter.clear();
        adapter.add(schedule.getDay(currentIndex).getList().get(0));
        adapter.notifyDataSetChanged();
    }

    @Override
    public Object instantiateItem(ViewGroup container, int index) {

        LayoutInflater inflater = (LayoutInflater) container.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View layout = inflater.inflate(R.layout.schedule_list_view, null);

        ListView view = new ListView(container.getContext());

        adapter = new ArrayAdapter<Course>(container.getContext(), 
                R.layout.list_view_child, schedule.getDay(index).getList());
        view.setAdapter(adapter);

        //TEST CODE!!!! This does not yield any sort data items in the list views!?
        adapter.add(new Course("test", "test", "test", "test", "test", "test", "test"));

        currentIndex = index;

        ((ViewPager) container).addView(layout);

        return layout;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {

        ViewPager pager = (ViewPager) container;
        View view = (View) object;

        pager.removeView(view);
    }

    /**
     * Gets the pageTitle, which is the name of the day that is at position.
     * 
     * @param position the index of the day selected.
     * @return the name of the day the index refers to.
     */
    @Override
    public CharSequence getPageTitle(int position) {
        return schedule.getDay(position).getThisDay();
    }

    @Override
    public int getCount() {
        return 6;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }
}
  • 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-11T09:26:34+00:00Added an answer on June 11, 2026 at 9:26 am

    If that is the full code for the instantiateItem method then it’s normal that you don’t see any data in the lists. You inflate the layout file named R.layout.schedule_list_view(in which you, most likely, have a ListView) and in the same instantiateItem method you create an independent ListView widget on which you set the data. As the data is binded to the ListView which is not in the layout file, you don’t see anything as the original ListView remains empty.

    The solution is to either set the data on the ListView that is in the inflated layout(R.layout.schedule_list_view) if you have it there, or add the created ListView with data to the inflate layout(layout(this is a View, so you would want to cast it to a ViewGroup or a subclass of ViewGroup)).

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

Sidebar

Related Questions

I have a ViewPager within a Fragment which contains three Fragments we'll call V1,
I want to have left and right buttons on my views within the ViewPager.
I have a project using a ViewPager which works correctly: I can page from
I have a fragment which contains a ViewPager. The ViewPager is associated with an
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 a ViewPage within which I would like to specify an external style
In my application I am using ViewPager from the support library- v4 In main
I have a ViewPager on my Kindle Fire app that adds roughly 30 views
There are information that it is impossible to use ViewPager within a Fragment in

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.