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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:44:12+00:00 2026-06-14T10:44:12+00:00

So I have an application with 3 actionbar.Tabs that switch between 3 fragments. Within

  • 0

So I have an application with 3 actionbar.Tabs that switch between 3 fragments. Within two of these fragments I need to have a ViewPager that switches between about 6 ListViews. The problem is that Fragment display page that I’m trying to get this to work on, just shows black…always…I’ve confirmed that I can display other stuff (I tried making my SherlockFragment a SherlockListFragment and I could display data in that). So the problem is solely confined to my adapter and my ViewPager, and the code that puts them in place. Oh I should also mention that I’m using ActionBarSherlock, and (trying to) ViewPagerIndicator. Which I have imported correctly (finally).

So here’s the code for my Fragment:

import vt.finder.schedule.Schedule;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import com.actionbarsherlock.app.SherlockFragment;
import com.viewpagerindicator.TitlePageIndicator;


public class FreeTimeFragment extends SherlockFragment {

//~Data Fields--------------------------------------------
/**
 * Adapter used for swiping between days.
 */
private ViewPager dayPage;
/**
 * The DayAdapter that is used to switch between course Lists for each day for the listView.
 */
private DayAdapter dayAdapt;


//~Constructors--------------------------------------------
@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    View view = onCreateView(getLayoutInflater(savedInstanceState), null, savedInstanceState);

    LinearLayout layout = (LinearLayout) view.findViewById(R.id.linear_layout);
    dayPage = (ViewPager) layout.findViewById(R.id.free_time_day_pager);

    Schedule freeTime = getArguments().getParcelable("freeTime");

    dayAdapt = new DayAdapter(freeTime);
    //Bind the title indicator to the adapter
    TitlePageIndicator titleIndicator = (TitlePageIndicator) layout.findViewById(R.id.titles);
    dayPage.setAdapter(dayAdapt);
    titleIndicator.setViewPager(dayPage);
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)     {

    View view = inflater.inflate(R.layout.free_time_fragment_layout, container, false);
    return view;
}
}

Here’s the code for my adapter:

import vt.finder.schedule.Course;
import vt.finder.schedule.Schedule;
import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;


/**
 * PageAdapter class, provides functionality for switching between days of
 * the week.
 * 
 *
 */
public final class DayAdapter extends PagerAdapter {

    //~Data Fields----------------------------------------//
    /**
     * The list adapter that the current list is being handed to.
     */
    private Schedule schedule;

    //~Constructors---------------------------------------//
    public DayAdapter(Schedule theSchedule) {

        schedule = theSchedule;
    }

    //~Methods--------------------------------------------//
    @Override
    public Object instantiateItem(ViewGroup container, int index) {

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

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

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

        return container;
    }

    @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 == (View) object;
    }
}

and here’s my xml file for the fragment layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:weightSum="1"
    android:id="@+id/linear_layout">

    <com.viewpagerindicator.TitlePageIndicator
        android:id="@+id/titles"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1.09" />

    <android.support.v4.view.ViewPager
        android:id="@+id/free_time_day_pager"
        android:layout_width="fill_parent"
        android:layout_height="284dp" />

    <RelativeLayout
        android:id="@+id/relativeLayout1"
        android:layout_width="match_parent"
        android:layout_height="52dp"
        android:layout_weight="0.07" >

        <Button
            android:id="@+id/getScheduleButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:onClick="getScheduleClicked"
            android:text="@string/get_schedule" />

        <Button
            android:id="@+id/compareWithFriends"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/getScheduleButton"
            android:layout_alignParentRight="true"
            android:layout_toRightOf="@+id/getScheduleButton"
            android:onClick="compareWithFriendsClicked"
            android:text="@string/compare_with_a_friend" />

    </RelativeLayout>

</LinearLayout>

And I suppose I should mention briefly that Schedule, holds Day objects, which hold Lists of Courses, which are to be displayed. All of that code most definitely works, I’ve been using it for months.

  • 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-14T10:44:13+00:00Added an answer on June 14, 2026 at 10:44 am

    Hey I figured it out by my self i was using ViewPager to Make Gallery along with FragmentPagerAdapter..!

    i added

    @Override
            public void destroyItem(ViewGroup container, int position, Object object) {
                // TODO Auto-generated method stub
    
                    FragmentManager manager = ((Fragment) object).getFragmentManager();
                    FragmentTransaction trans = manager.beginTransaction();
                    trans.remove((Fragment) object);
                    trans.commit();
    
                super.destroyItem(container, position, object);
            }
    

    To my FragmentPagerAdapter to remove view to avoid overheads.! 🙂

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

Sidebar

Related Questions

Now that we have two Icons (Dark and Light) as described in ActionBar Icon
I have an Android application for pre-Honeycomb devices that uses custom tabs to launch
I have application which uses Sherlock ActionBar package. The application uses platform-specific behavior for
I have this application where I implement the ActionBar Fragment interface. Underlying the interface,
I'm developing a simple Android application that would have an action bar on the
I have application where i have two view controllers my first view and second
I have application that makes different queries with different results so the caching in
I have started currently an portfolio application for HoneyComb tablet. I have used ActionBar.Tab
I noticed that for older devices running the FB application it doesn't have action
In my application, I have three tabs in the Action Bar. Tab 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.