ViewPagerIndicator's TitlePageIndicator stopping fragments from showing and causing swiping to not work

StackOverflow https://stackoverflow.com/questions/9322988

Question

I'm seeing a very strange error when trying to use ViewPagerIndicator (http://viewpagerindicator.com/). I've narrowed it down to the TitlePageIndicator that is part of that library. When I use the TitlePageIndicator, I am unable to swipe between tabs, and my fragments don't show up (although they are created and ran, the button in the upper right is created by the fragment that should be showing). It looks like this: http://imgur.com/RJaI9 (Sorry, new user so I can't inline pictures)

But without, my fragments appear correctly and I'm able to swipe between them. http://imgur.com/bboSd

I have no idea why this is happening. I'm using the latest ViewPagerIndicator library, but I'm thinking maybe it has something to do with how I imported it? I followed the instructions on the website: created the new android project in eclipse from existing source, imported the compatibility library, then added it to my project in the android project properties.

Any help would be greatly appreciated, I've been stuck on this for 2 weeks :(

Code:

Layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.viewpagerindicator.TitlePageIndicator
    android:id="@+id/titles"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />
<android.support.v4.view.ViewPager
    android:id="@+id/grocery_pager"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
     />
</LinearLayout>

FragmentActivity (From ActionBarSherlock):

public class GroceryActivity extends BaseFragmentActivity
{
   @Override
   protected void onCreate(Bundle savedInstanceState)
   {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_grocerylist);
  // Set the pager with an adapter
  ViewPager pager = (ViewPager) findViewById(R.id.grocery_pager);
  pager.setAdapter(new GroceryViewPagerAdapter(getSupportFragmentManager()));

  // Bind the title indicator to the adapter
//When these next two lines are commented out, everything works
  TitlePageIndicator titleIndicator = (TitlePageIndicator) findViewById(R.id.titles);
  titleIndicator.setViewPager(pager);
  }
}
Was it helpful?

Solution

I ended up finding the problem:

In my linear layout, I did not set the orientation of the layout. For some silly reason I thought the orientation field had to do with the orientation of the device, and not the layout itself. Adding the orientation:vertical field made everything work.

Hopefully this helps someone!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top