【发布时间】:2015-04-10 22:54:35
【问题描述】:
我在我的视图中使用谷歌的 SlidingTabLayout,但我想动态地添加新的标签。 我正在使用这个http://developer.android.com/samples/SlidingTabsBasic/src/com.example.android.common/view/SlidingTabLayout.html
这是我初始化它的代码:
// Create the adapter that will return a fragment for each of the three
// primary sections of the activity.
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
//this ^ is a FragmentStatePagerAdapter
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
// Assiging the Sliding Tab Layout View
tabs = (SlidingTabLayout) findViewById(R.id.tabs);
// Setting the ViewPager For the SlidingTabsLayout
tabs.setViewPager(mViewPager);
我完全不知道如何添加标签。
我想过改变 ViewPager 但在 SlidingTabLayout 中有一条评论:
/**
* Sets the associated view pager. Note that the assumption here is that the pager content
* (number of tabs and tab titles) does not change after this call has been made.
*/
public void setViewPager(ViewPager viewPager) {
【问题讨论】:
-
这可能与您预想的设计有些不同,但请看一下这个类 - 尽管没有标签,但它可能会满足您的需求:github.com/daimajia/AndroidSwipeLayout
-
我需要标签。不过还是谢谢
标签: android android-fragments android-viewpager android-pageradapter fragmentstatepageradapter