You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Alert Dialog确认按钮异常:点击放弃修改无法返回主页

问题修复:点击「放弃修改」未返回主页

问题根源

你的MainActivity中removeEditPane方法调用了未实现的removeFragment函数,导致编辑页的AddEditFragment没有被正确移除,因此点击确认弹窗的「放弃修改」后,仅弹窗关闭,编辑页仍停留在界面上。

修复方案

方案1:实现removeFragment方法

在MainActivity中添加以下方法,确保正确移除目标Fragment:

private fun removeFragment(fragment: Fragment) {
    supportFragmentManager.beginTransaction()
        .remove(fragment)
        .commit()
}

方案2:直接在removeEditPane中使用Fragment事务

修改removeEditPane方法,将未实现的removeFragment调用替换为直接的Fragment事务:

private fun removeEditPane(fragment: Fragment? = null) {
    Log.d(TAG, "removeEditPane called")
    if (fragment != null) {
        // 替换原removeFragment调用为以下代码
        supportFragmentManager.beginTransaction()
            .remove(fragment)
            .commit()
    }

    // 原有逻辑保持不变
    task_details_container.visibility = if (mTwoPane) View.INVISIBLE else View.GONE
    mainFragment.visibility = View.VISIBLE
    supportActionBar?.setDisplayHomeAsUpEnabled(false)
}

验证逻辑

修复后,当你点击「放弃修改」时:

  1. AppDialog会触发MainActivity的onPositiveDialogResult回调
  2. 回调中调用removeEditPane,正确移除编辑Fragment并切换显示主页
  3. 最终实现返回主页的预期效果

内容的提问来源于stack exchange,提问作者Muhab Al-Afandi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 14:45:26