Question

Hi im using viewpageindicator and have setup a viewpager and fragments that works like a charm! The problem is that I dont seem to get the TitlePageIndicator to work. It is just empty and dosnt show anything.

<android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/indicator"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/textView2" >

    </android.support.v4.view.ViewPager>

   <com.viewpagerindicator.TitlePageIndicator
        android:id="@+id/indicator"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:padding="10dip"
        android:visibility="visible"
        app:linePosition="top" 
        android:theme="@style/CustomUnderlinePageIndicator"/> 

suspect that something goes wrong with the styles. i use the style file from the viewpageindicator sample.

When i exicute this code I get following logcat error :

mPager = (ViewPager)findViewById(R.id.pager);

    mPager.setAdapter(mAdapter);

    mIndicator = (TabPageIndicator)findViewById(R.id.indicator);
    mIndicator.setViewPager(mPager);

error: java.lang.ClassCastException: com.viewpagerindicator.TitlePageIndicator cannot be cast to com.viewpagerindicator.TabPageIndicator

Was it helpful?

Solution

In your XML change TitlePageIndicator for TabPageIndicator or in your file change mIndicator = (TabPageIndicator)findViewById(R.id.indicator); for mIndicator = (TitlePageIndicator)findViewById(R.id.indicator); why is it different

OTHER TIPS

use this code

mPager = (ViewPager) findViewById(R.id.view_pager); mPager.setAdapter(mAdapter);

    mIndicator = (TitlePageIndicator) findViewById(R.id.title_indicator);
    mIndicator.setViewPager(mPager);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top