• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

TabHost Remove Tab problem

 
Prajkti Khadse
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

In my application, i am creating Tabs Programmatically and and i want to remove them as well one by one.
I tried removeViewAt() and it works too.

But, after deleting my application gets crashed.
e.g. If i have three tabs Tab1, Tab2 and Tab3 and if i remove Tab2, it gets removed but as soon as i click either of the tabs Tab1 or Tab2, ithe application gets crashed and on Log Cat i see this Error Message :

AndroidRuntime(766): Uncaught handler: thread main exiting due to uncaught exception
AndroidRuntime(766): java.lang.NullPointerException
AndroidRuntime(766): at android.widget.TabWidget.onFocusChange(TabWidget.java:241)
AndroidRuntime(766): at android.view.View.onFocusChanged(View.java:2382)

...
AndroidRuntime(766): at android.view.ViewGroup.removeViewInternal(ViewGroup.java:2016)
AndroidRuntime(766): at android.view.ViewGroup.removeViewAt(ViewGroup.java:1970)


can anyone please please Help me?
 
Monu Tripathi
Rancher
Posts: 1369
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[Caveat: I have only read about TabWidgets, never worked on them as much as I'd have liked, so what I say here might be a little obsolete. Better solutions might exist...]

Adding tabs dynamically to a TabHost is easy. You create a TabSpec and keep adding them to the TabHost.
However, deleting the tabs is not (as easy).You might want to read this thread and this issue.

The easiest approach to deleting Tabs, that I can think of is(it comes at cost of more memory):
1. Remember all the TabSpecs that you are adding to your TabHost.
2. When the time comes to delete a Tab, remove the TabSpec first from your memory
3. Clear all the tabs from the TabHost
4. Recall all the TabSpecs in your memory and add them back.



Hope that helps....
 
Prajkti Khadse
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You So Much Monu.
It worked

Thanks a Lot...!!
 
Monu Tripathi
Rancher
Posts: 1369
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you're welcome!
 
Bill Zelan
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The internal pointer to the current tab has to be reset in some cases, else your application will crash. To to this, add the following line before your clearAllTabs() call;

myTabHost.setCurrentTab(0); //IMPORTANT
myTabHost.clearAllTabs(); // clear all tabs from the tabhost

Hopes this saves you some trouble!
 
jetti madhu
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
When i am trying to remove a tab. When i use
myTabHost.clearAllTabs() ; ---------It displays the NullPointerException.

And is there any way to delete dynamic generated particular tabs from list of tabs?

Thanks
Jetti
 
Titus Abraham
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello ,


I have tried all the above methods but none works.. Any idea how to clear off all the tabs

Thanks,
Titus
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic