Deleted
Last edited by a moderator:
Which problem?I think that for this problem is no solution, otherwise it would have already solved Erel.
SetActivityAttribute(b4a.example.actcustomdialog, android:theme, @android:style/Theme.Translucent.NoTitleBar)
... A regular panel will behave better, even if the developer needs to add three lines of code to Activity_Keypress event.
I do not know what they are but I trustIt would be nice if one could also program Modale dialogues with B4x.
Public Sub CallFromKeyPress(Keycode As Int) As Boolean
If DialogIsVisible AND Keycode = 4 Then '4 = BACK
'close dialog
Return True
Else
Return False
End If
End Sub
Sub Activity_KeyPress (KeyCode As Int) As Boolean
If MyDialog.CallFromKeyPress(KeyCode) Then Return True
'other code here if needed
End Sub
Modal dialogs are being replaced with async dialogs: DoEvents deprecated and async dialogs (msgbox)It would be nice if one could also program Modale dialogues with B4x
[/code]
The user will call it with:
B4X:Sub Activity_KeyPress (KeyCode As Int) As Boolean If MyDialog.CallFromKeyPress(KeyCode) Then Return True 'other code here if needed End Sub
Public Sub Initialize(MyActivity As Activity, Me_CallBack As Object,EventName As String)
My=MyActivity
CallBack=Me_CallBack
If EventName.IndexOf("_")=-1 Then Event=EventName & "_Response" Else Event="@" & EventName
IsInitialized=True
Dim E As EditText
E.Initialize("")
MyActivity.AddView(e,-30dip,-30dip,30dip,30dip)
e.RequestFocus
SetReflector(e)
End Sub
Public Sub SetReflector(v As View)
Dim r As Reflector
r.Target = v
r.SetOnKeyListener("On_KeyPress")
r.RunMethod2("setFocusable", "True", "java.lang.boolean")
r.RunMethod2("setFocusableInTouchMode", "True", "java.lang.boolean")
End Sub
Private Sub On_KeyPress(ViewTag As Object, KeyCode As Int, KeyEvent As Object) As Boolean
If KeyCode = KeyCodes.KEYCODE_BACK Then
Dim j As JavaObject = KeyEvent
Dim eventCode As Int = j.RunMethod("getAction",Null)
If (eventCode = 0) Then
Response=DialogResponse.CANCEL
Pan.RemoveView
T.Enabled=False
If SubExists(CallBack,Event) Then CallSub2(CallBack,Event,Response)
If SubExists(CallBack,Event.Replace("@","")) And Event.IndexOf("@")>-1 Then CallSub(CallBack,Event.Replace("@",""))
End If
Return True
Else
Return False
End If
End Sub