0

好的,我将尝试尽可能简单地解释这一点!我确定我忽略了一些简单的东西 - 但盯着屏幕太久而无法识别。一如既往,感谢您的帮助!

在我的主要活动中,我有:

Sub Activity_KeyPress (KeyCode As Int) As Boolean 'handles the back key and the menu key
    If KeyCode = KeyCodes.KEYCODE_BACK Then 'back keySub Activity_KeyPress (KeyCode As Int) As Boolean                          
        Quitandsave
    End If
    Return True
End Sub

Sub - Quitandsave 将面板视图添加到当前活动(在 Main 中) - 面板上有两个按钮 - 是退出和否(改变主意并返回应用程序)。

我发现当按下返回键时 - 面板显示正确,并且是/否按钮工作正常。

但是,如果在最初按下后退键时可以看到面板,然后再次按下后退键(故意或意外) - 是按钮仍然有效(面板删除、文件保存、应用程序退出),但否按钮不 - 就像它被冻结 - 并且面板不会删除。是因为初始化吗?... 或者是其他东西?

这是我的是/否按钮代码:

Sub quitsavebtn1_Click ' yes - quit and save
    WriteMapSavePage 'calls a sub that writes map to int or external space
    Activity.Finish ' exit the application
End Sub

Sub quitsavebtn2_Click 'no - don't quit and save
    quitsavepnl.RemoveView 'remove the panel to continue using app
End Sub

在我的 Quitandsave Sub 中:

Sub Quitandsave
    quitsavepnl.Initialize("quitsavepnl")
    .... code here to set colors,font etc.
    Activity.AddView(quitsavepnl,15dip,15dip, 50%x, 50%y)
    .... code here to add buttons to panel etc.
    quitsavepnl.Visible = True
End Sub
4

3 回答 3

2

RemoveView 并没有按照您的想法做。它只是将面板与其父级分离。使用 Msgbox 会更好,但您可以尝试 quitsavepnl.Visible = False 。

于 2011-10-23T14:39:49.027 回答
1

Try removing this line, and see if it works:

quitsavepnl.RemoveView

You may need a Timer to remove the view after the click event is finished.

于 2011-10-23T14:13:45.957 回答
0

尝试将函数 quitsavebtn2_Click 更改为以下内容:

Sub quitsavebtn2_Click ' no - don't quit and save
    If quitsavepnl.IsInitialized then
        quitsavepnl.Visible = false ' remove the panel to continue using app

    End if

End Sub

...以及 QuitandSave 函数如下:

Sub QuitandSave
    If Not(quitsavepnl.IsInitialized) then
        quitsavepnl.Initialize("quitsavepnl")
        ' .... code here to set colors,font etc.

        Activity.AddView(quitsavepnl, 15dip, 15dip, 50%x, 50%y)
        ' .... code here to add buttons to panel etc.

    End If

    If quitsavepnl.IsInitialized then
        quitsavepnl.Visible = True

    End If

End Sub

使上面的代码如此高效的原因在于它可以与 Java 一起使用:

  • Panel 将一直存在,直到 Java 的垃圾收集器删除 Panel 以释放内存。
  • 然后在下次调用 QuitandSave 时重新创建面板。
于 2013-10-30T10:40:36.733 回答