Android OnTabChangingListener
TabHost 小部件有一个 setOnTabChangedListener() 方法,用于在选项卡更改时运行代码,但我需要在选项卡更改之前运行代码,以便验证输入的数据。这可能吗?我正在考虑使用点击侦听器,但让它检测对项目的点击似乎很麻烦,而且我仍然不确定如何取消更改选项卡并显示消息。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道您是否可以在更改选项卡之前检查某些内容,但是还有另一种选择。当选项卡更改时,执行检查,如果输入的数据无效,请更改选项卡的内容视图以显示消息,或者将其清空并弹出一个解释错误的消息框。从那里您可以设置对话框,以便在关闭时调用 setCurrentTab(int index) 返回到提示输入的选项卡。
有帮助吗?
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?