I have a TabLayout and inside that I have ViewPager. I need to dynamically add and remove tab in tablayout(material design). I can able to add the tabs dynamically but while
Remove tab from TabLayout
...
public void removeTab(int position) {
if (mTabLayout.getTabCount() >= 1 && position
Add a removeTabPage method to your PagerAdapter
...
public void removeTabPage(int position) {
if (!tabItems.isEmpty() && position
Add a Tab
...
private void addTab(String title) {
mTabLayout.addTab(mTabLayout.newTab().setText(title));
mPagerAdapter.addTabPage(title);
}
...
Add a addTabPage method to your PagerAdapter
...
public void addTabPage(String title) {
tabItems.add(title);
notifyDataSetChanged();
}
...
Check out this sample code for a full example: ...samples/SupportDesignDemos/src/com/example/android/support/design/widget/TabLayoutUsage.java