Hi all.
I wrote a little class for an input dialog.
In the class clsDialog I want catch the BackKey. It should not close the whole application, only the actual class instance.
If only the first dialog is started it works like expected: the dialog is closed and the main activity not.
If from the first dialog the second dialog is started with the button "Edit city", the BackKey will close both dialogs and not only the city dialog. In the eventhandler
Sub On_KeyPress(ViewTag As Object, KeyCode As Int, KeyEvent As Object) As Boolean
the return value is "True" so the BackKey event should be consumed!
Why this eventhandler is called 2 times??? See Log("On_KeyPress")
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
Has anyone an idea?
Thanks Lutz
			
			I wrote a little class for an input dialog.
In the class clsDialog I want catch the BackKey. It should not close the whole application, only the actual class instance.
If only the first dialog is started it works like expected: the dialog is closed and the main activity not.
If from the first dialog the second dialog is started with the button "Edit city", the BackKey will close both dialogs and not only the city dialog. In the eventhandler
Sub On_KeyPress(ViewTag As Object, KeyCode As Int, KeyEvent As Object) As Boolean
the return value is "True" so the BackKey event should be consumed!
Why this eventhandler is called 2 times??? See Log("On_KeyPress")
			
				B4X:
			
		
		
		Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.
End Sub
Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
 
   ' in layout Main
   Private btnDialog As Button
   Private pnlMain As Panel
   
   ' in layout names
   Private btnCity As Button
   Private edtName1 As EditText
   Private edtName2 As EditText
   Private lblName1 As Label
   Private lblName2 As Label
   Private pnlNames As Panel
   
   ' in layout city
   Private edtCity As EditText
   Private edtStreet As EditText
   Private lblCity As Label
   Private lblStreet As Label
   Private pnlAdress As Panel
   
   ' 2 instances of class dialog
   Private dlgNames As clsDialog
   Private dlgAdress As clsDialog
End Sub
Sub Activity_Create(FirstTime As Boolean)
   'Do not forget to load the layout file created with the visual designer. For example:
   Activity.LoadLayout("Main")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub btnDialog_Click
   Dim pnlDialog1 As Panel
   
   pnlDialog1.Initialize("")
   pnlDialog1.LoadLayout("names")  ' includes pnlNames
   
   dlgNames.Initialize(Activity, pnlNames, edtName1)
   dlgNames.Show
End Sub
Sub btnCity_Click
   Dim pnlDialog2 As Panel
   
   pnlDialog2.Initialize("")
   pnlDialog2.LoadLayout("city")  ' includes pnlAdress
   
   dlgAdress.Initialize(Activity, pnlAdress, edtCity)
   dlgAdress.Show
End Sub
'--------------------------------------------------
' this is the class dialog: clsDialog
'--------------------------------------------------
Sub Class_Globals
   Private aAct As Activity
   Private aPnlInput As Panel
   Private aFirstEditText As EditText
   Private pnlScreen As Panel
End Sub
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(act As Activity, pnlInput As Panel, firstEditText As EditText)
   aAct = act
   aPnlInput = pnlInput
   aFirstEditText = firstEditText
End Sub
Public Sub Show
   pnlScreen.Initialize("pnlScreen")
   aAct.AddView(pnlScreen, 0, 0, aAct.Width, aAct.Height)
   pnlScreen.Color = Colors.ARGB(150, 0, 0, 0)
   pnlScreen.BringToFront
   
   aPnlInput.RemoveView
   pnlScreen.AddView(aPnlInput, _
    (aAct.Width - aPnlInput.Width)/2, _
                    (aAct.Height - aPnlInput.Height)/2, _
                    aPnlInput.Width, aPnlInput.Height)
                   
   aFirstEditText.RequestFocus
   
   ' for all EditText fields set the eventhandler for KeyPress
   For Each v As View In aPnlInput.GetAllViewsRecursive
     If v Is EditText Then
       SetReflector(v)
     End If
   Next
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 Hide
   pnlScreen.RemoveView
End Sub
Private Sub pnlScreen_Click
   ' Do Nothing: Prevent panel from click
End Sub
Private Sub On_KeyPress(ViewTag As Object, KeyCode As Int, KeyEvent As Object) As Boolean
   If KeyCode = KeyCodes.KEYCODE_BACK Then
     Log("On_KeyPress")
    Hide
    Return True
   Else
     Return False
   End If
End SubHas anyone an idea?
Thanks Lutz
 
				 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		