views:

41

answers:

1

The TabHost widget has a setOnTabChangedListener() method to run code when the tab changes, but I need to run code before the tab changes, in order to validate the data entered. Is this possible? I was thinking about using a click listener but it seems like it would be fiddly to get it to detect clicks on items, and I'm still not sure how you'd cancel changing the tab and show a message.

A: 

I do not know if you can check something before the tab is changed, however there is an alternative. when the tab is changed, perform your checks, and if the data entered isnt valid, change the content view of the tab to display the message, or make it empty and pop a message box explaining the error. from there you can set up the dialog so when it's closed it calls setCurrentTab(int index) to return to the tab that is prompting for input.

does that help?

mtmurdock
Sounds like a good idea, but how would the tab (effectively a standalone activity) get a reference to the tab host?
Echilon
Make the TabHost a static public/protected member variable of the tab activity. this will allow other activities to access it. then when you want to access it you would just reference it.MyTabActivity.myTabHost.setCurrentTab(...)
mtmurdock