The TabHost widget has a setOnTabChangedListe开发者_StackOverflowner() 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.
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?
精彩评论