android:除非保存数据,否则阻止选项卡切换

发布于 2024-11-28 14:32:38 字数 656 浏览 0 评论 0原文

编辑:我想阻止用户切换选项卡,除非我收到保存数据警报的响应。我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

玩心态 2024-12-05 14:32:38

您必须扩展 TabHost 类并重写 setCurrentTab 方法,然后您可以添加自己的 onBeforeTabchanged() 回调。

You would have to extend the TabHost class and override the setCurrentTab methods then you could add your own onBeforeTabchanged() callback.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文