Viewpager Title Doesn't Appear Until I Swipe It
Solution 1:
It is an issue appeared in com.android.support:appcompat-v7:23.0.0. You can refer here https://code.google.com/p/android/issues/detail?id=183127
In that link google support team have mention that defect would be fixed in future releases. So for now solution is build the project using com.android.support:appcompat-v7:22.2.1
Update : If feasible for you then you can go ahead with another solution provided by @nidheeshdas. I have tried on simple project; it work Modified solution of @nidheeshdas inside onResume() of Activity
viewPager.setCurrentItem(1);
viewPager.postDelayed(newRunnable() {
@Overridepublicvoidrun() {
viewPager.setCurrentItem(0);
}
},100);
New Update: As mentioned in the above google issue tracker link and comments from JP Ventura. I have tried with new version of library and issue seems to be fixed.
Solution 2:
Instead of using android.support.v4.view.PagerTabStrip , use android.support.design.widget.TabLayout for displaying tabs for viewPager. It is included in Google Design Support Library.
See this link for more information http://android-developers.blogspot.in/2015/05/android-design-support-library.html
Just few lines:
viewPager=(ViewPager)v.findViewById(R.id.viewPager);
ViewPagerAdapter adapter=new ViewPagerAdapter(this.getChildFragmentManager(),doctor);
adapter.setViewPagerFragmentListener(this);
viewPager.setAdapter(adapter);
tabLayout.setupWithViewPager(viewPager); //Sync Tabs with viewPager
tabLayout.setTabsFromPagerAdapter(adapter); //Setup tabs titles
And to change the titles use the following code in ViewPagerAdapter
@Overridepublic CharSequence getPageTitle(int position) {
switch (position){
case0:
return"Title 1";
case1:
return"Title 2";
case2:
return"Title 3";
}
returnsuper.getPageTitle(position);
}
Solution 3:
I also recently started to have this problem, and after a little bit of testing I think I found a bug in Android's latest support package update.
The problem appears in to be in com.android.support:appcompat-v7:23.0.0.
Try changing the dependency back to com.android.support:appcompat-v7:22.2.1 (second latest update) and see if that works.
Unfortunately, I have yet to find any solution to get it to work with the latest support package update.
Solution 4:
Try this. Its seems to be working for me.
@OverrideprotectedvoidonResume() {
super.onResume();
pager.setCurrentItem(1);
Task.delay(500).continueWith(newContinuation<Void, Object>() {
@OverridepublicObjectthen(Task<Void> task) throws Exception {
pager.setCurrentItem(0);
returnnull;
}
}, Task.UI_THREAD_EXECUTOR);
}
onResume set the pager to 1 and then back to 0. This makes the title appear the page loads the first time.
Post a Comment for "Viewpager Title Doesn't Appear Until I Swipe It"