14

I have the following simple setup:

swipeable.xml

<LinearLayout
    android:id="@+id/content_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <include layout="@layout/toolbar" />

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <android.support.v4.view.PagerTabStrip
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
    </android.support.v4.view.ViewPager>
</LinearLayout>

Activity:

public class InfoActivity extends ActionBarActivity {

  private static final int[][] KEYS = { { R.string.usage, R.string.usage_text }, 
                                        { R.string.data_protection, R.string.data_protection_text }, 
                                        { R.string.impressum, R.string.impressum_text } };

  @Override
  protected void onCreate( Bundle savedInstanceState ) {
    setContentView( R.layout.swipeable );
    super.onCreate( savedInstanceState );
    ViewPager viewPager = (ViewPager)findViewById( R.id.pager );
    viewPager.setAdapter( new SwipeAdapter( getSupportFragmentManager() ) );
  }

  class SwipeAdapter extends FragmentStatePagerAdapter {

    public SwipeAdapter( FragmentManager fm ) {
      super( fm );
    }

    @Override
    public Fragment getItem( int position ) {
      Bundle b = new Bundle();
      b.putInt( "key", KEYS[ position ][ 1 ] );
      return Fragment.instantiate( InfoActivity.this, InfoFragment.class.getName(), b );
    }

    @Override
    public int getCount() {
      return KEYS.length;
    }

    @Override
    public CharSequence getPageTitle( int position ) {
      return getString( KEYS[ position ][ 0 ] ).toUpperCase();
    }
  }      
}

If I access the activity the 1st time, no pagerstrip-texts are shown. If I swipe or click the tab, the texts are displayed normally:

enter image description here

What could be the reason for such a strange behavior?

injecteer
  • 20,038
  • 4
  • 45
  • 89

1 Answers1

23

For me this issue happened after I updated the support-v13 (or v4), appcompat-v7, recyclerview-v7 and design libraries to 23.0.0. I guess it is a bug. After downgrading it to 22.2.1, it is working fine.

I would suggest to wait until they release new revision of these libraries.

Update: This issue is occurring only in appcompat-v7 and design libs, which has now got fixed in 23.1.0 revision of Android Support Library.

krishh
  • 1,551
  • 15
  • 28
  • 1
    yes, I updated another app with 23.0.0 and got the same results out of nowhere – injecteer Aug 24 '15 at 11:21
  • 1
    This issue is reported here https://code.google.com/p/android/issues/detail?id=183127 – Jon Sep 01 '15 at 17:20
  • I had the same issue. Thanks for helpful advice! – hornet2319 Sep 10 '15 at 13:41
  • @Krishnan: Excuse me, I got this, too. Could you please show how to downgrade build tool from 23.0.0 to 22.2.1? :(. I had tried but got the error when building app. Thanks for your help. – Neo Sep 15 '15 at 10:06
  • 1
    @MrNeo, in eclipse you have to copy the `android-support-v4.jar` of the previous version into the `libs/` – injecteer Sep 15 '15 at 12:27
  • @MrNeo As _injecteer_ said, if you have taken a backup of `22.2.1` version of `appcompat-v7`library, replace current one with this previous version. For instructions you can always check [official guide](http://developer.android.com/tools/support-library/setup.html#add-library). `appcompat-v7` library already have `support-v4` library. So no need to add it separately. – krishh Sep 16 '15 at 13:33
  • 1
    They have released the the 23.0.1 revision of Android Support Library. But this issue has not fixed yet. Let's hope they will fix this in coming revision. – krishh Sep 16 '15 at 13:35
  • @Krishnan: Thanks, Sir. I had fixed this by downgrading from 23.0.1 to 22.0.1. Hope this problem could be fixed in the next. – Neo Sep 17 '15 at 01:52
  • @BrillPappin Yes. You are right. But this time tabs are not appearing, even after sliding to next tab. I think 24.0.0 is still beta. – krishh Jun 28 '16 at 09:33
  • Found that it's fixed with 23.2.0, upgrading allowed me to remove the workaround hacks I had in place. – Brill Pappin Jun 28 '16 at 12:56
  • @BrillPappin did you try with 23.4.0? It is the latest stable revision. – krishh Jun 28 '16 at 15:27
  • @krish I have evaluated this particular thing with 23.4.0 specifically, once it was off my radar, I didn't bother with it. – Brill Pappin Sep 10 '16 at 15:06
  • i meant i *have not* but apparently i can only edit a comment for 5 minutes. – Brill Pappin Sep 10 '16 at 15:14