I want to be able to add tabs to my TabHost.
My original tabwidget will have 2 tabs:
1 called 'Tab 1'
1 called 'Add Tab'
What I had hoped was for Upon the user clicking 'Add Tab' a new Tab to be generated so that I have 3 tabs
1 called 'Tab 1'
1 called 'Tab 2'
1 called 'Add Tab'
More tabs can be added this way, with 'Add Tab' always being the last tab.
When it came to coding, I could not find an 'insertTabAt' or even 'updateTab' method for TabHost.
So I thought I could just delete the 'Add Tab', Create my new 'Tab X' and recreate 'Add Tab'.
To delete the tab I used:
tabHost.getTabWidget().removeViewAt(index);
However this does not seem to work very well:
When public void onTabChanged(String tabId) is called, after clicking on my newly created 'Tab X', the tabId is still that of my original 'Add Tab'. (to make sure, my original and new 'Add Tab' have different tabId's)
After a quick browse, it looks like I might have to delete all tabs and regenerate them, I don't like the idea.
Has anybody ever tried to implement an add tab functionality similar to mine? it is a common UI feature on PCs. Alternatively, any tips on deleting tabs?
Note, except from 'Tab 1' all my tabs are created programatically.
TIA
Asked
Active
Viewed 1,216 times
0

user1654757
- 300
- 1
- 5
- 14
-
check this question http://stackoverflow.com/questions/4320303/how-to-add-tabs-dynamically-that-can-be-linked-to-a-users-choice-of-webpage – Jaiprakash Soni Sep 20 '12 at 04:58
-
Thanks JaiSoni, but the issue you pointed me to is a different one. Adding tabs can be done in a simple manner, my issue is that I want to delete the Tab content and their reference in the TabWidget. – user1654757 Sep 20 '12 at 10:40
-
for removing tabs check this question http://stackoverflow.com/questions/3299845/how-to-remove-tab-from-tabhost – Jaiprakash Soni Sep 21 '12 at 03:47