Text in PagerTabStrip not displayed upon 1st view
Asked Answered
D

1

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?

Dateless answered 23/8, 2015 at 16:12 Comment(0)
G
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.

Garlinda answered 24/8, 2015 at 11:3 Comment(12)
yes, I updated another app with 23.0.0 and got the same results out of nowhereDateless
This issue is reported here code.google.com/p/android/issues/detail?id=183127Fauch
@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.Dusk
@MrNeo, in eclipse you have to copy the android-support-v4.jar of the previous version into the libs/Dateless
@MrNeo As injecteer said, if you have taken a backup of 22.2.1 version of appcompat-v7library, replace current one with this previous version. For instructions you can always check official guide. appcompat-v7 library already have support-v4 library. So no need to add it separately.Garlinda
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.Garlinda
@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.Dusk
@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.Garlinda
Found that it's fixed with 23.2.0, upgrading allowed me to remove the workaround hacks I had in place.Yorgos
@BrillPappin did you try with 23.4.0? It is the latest stable revision.Garlinda
@krish I have evaluated this particular thing with 23.4.0 specifically, once it was off my radar, I didn't bother with it.Yorgos
i meant i have not but apparently i can only edit a comment for 5 minutes.Yorgos

© 2022 - 2024 — McMap. All rights reserved.