android:除非保存数据,否则阻止选项卡切换
编辑:我想阻止用户切换选项卡,除非我收到保存数据警报的响应。我有一个 onTabChangedlistener 来检查切换选项卡时的数据更改。
mTabHost.setOnTabChangedListener(this);
@Override
public void onTabChanged(String tabId) {
// TODO Auto-generated method stub
if (mTabHost.getCurrentTab()==1 && dataModified){
AlertMessage(this, "Your data was NOT saved! Press Ok to continue, or Cancel to stay on the current screen. ");
}
}}
使用 onPause 也会给出相同的结果..在用户可以响应“确定”/“取消”之前切换选项卡。
我的问题是,当警报显示选项卡已切换时。我希望用户响应“确定”/“取消”,然后只执行所需的操作(停留在选项卡或切换选项卡上)。
我怎样才能获得用户响应,然后只允许切换选项卡。
谢谢
EDIT: I want to prevent the user from switching tabs unless i get a response for my alert to save data. I have a onTabChangedlistener to check data change when switching tabs.
mTabHost.setOnTabChangedListener(this);
@Override
public void onTabChanged(String tabId) {
// TODO Auto-generated method stub
if (mTabHost.getCurrentTab()==1 && dataModified){
AlertMessage(this, "Your data was NOT saved! Press Ok to continue, or Cancel to stay on the current screen. ");
}
}}
Using onPause also gives the same result..tab switches before the user can respond ok/cancel.
My problem is that by the time the alert shows the tab is already switched. I want the user to respond ok/cancel and then only do the required(stay on the tab or switch tab).
How can i get the user response and then only allow switching of tabs.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须扩展 TabHost 类并重写 setCurrentTab 方法,然后您可以添加自己的 onBeforeTabchanged() 回调。
You would have to extend the TabHost class and override the setCurrentTab methods then you could add your own onBeforeTabchanged() callback.