Reputation: 31
I am trying to add and remove tabs the same way the demo does in my code. I have a toggle button that calls arrayAdapter.remove
from the remove()
method exactly how it is done the demo. When arrayAdapter.remove
is called the tab at the requested position is removed correctly but the changes are not reflected by the header for that tab. Also when I try to click on the last tab after removing one tab nothing happens but the tab I want to remove is removed. If this is the logic to rearrange the tabs how would I get rid of this null tab? I know the fragment for the tab is removed because when I try to swipe to it I can't get to it anymore. I am having similar problems with add()
to add tabs to the adapter.setTabsToShow()
is called when the toggle button is clicked and add()
and remove()
are the same as in the demo. I have posted my code below.
private void add(boolean before) {
int current=mViewPager.getCurrentItem();
SimplePageDescriptor desc=
new SimplePageDescriptor(buildTag(arrayAdapter.getCount()),
buildTitle(arrayAdapter.getCount()),0);
if (before) {
arrayAdapter.insert(desc, current);
}
else {
if (current < arrayAdapter.getCount() - 1) {
arrayAdapter.insert(desc, current + 1);
}
else {
arrayAdapter.add(desc);
}
}
}
private void remove() {
if (arrayAdapter.getCount() > 1) {
arrayAdapter.remove(1);
}
}
public void setTabsToSHow() {
remove();
}
Upvotes: 1
Views: 64