我在我的視圖中使用谷歌的SlidingTabLayout,但我想動態地添加新的標籤。 我使用這個http://developer.android.com/samples/SlidingTabsBasic/src/com.example.android.common/view/SlidingTabLayout.html如何將標籤添加到SlidingTabLayout?
這是我的代碼初始化:
// 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) {
這可能與您設想的設計稍有不同,但請看看這個班級 - 它可以做你需要的東西,儘管沒有標籤:https://github.com/daimajia/AndroidSwipeLayout/ – 2015-02-10 19:22:30
我需要標籤。但是,無論如何感謝 – maysi 2015-02-10 19:32:52