Emulate an click event ?

Hubert Brandel

Active Member
Licensed User
Longtime User
Hi,

I do normaly just call the event routine, but now I have a problem - maybe because of this lasy doing. I do this ...

I want to emulate the klick on a view (button or label):
B4X:
...
pbNeuGE_Click ' just call it
...
sub pbNeuGE_Click(...)
   ...
end sub
normaly this works fine, but the new call of pbNeuGE_Click is befor the end of the calling routine. Now I have a problem because of this delay.

So how do I realy create an event (emulate) for this click on the button or click on that label ?

Regards,
Hubert
 
Last edited:

Hubert Brandel

Active Member
Licensed User
Longtime User
I do have a read only screen with lables (no edittext, the need too much space). If the user touch onto the lable I use a edittext control (witch was hidden and disabled) put it to the positon, load the text, enable and show it.
Then I request the focus and use the java code from this forum to show the keyboard:

B4X:
Dim p As Phone
p.HideKeyboard(Activity) ' hide it
DoEvents
...      
Dim Obj1 As Reflector
Obj1.Target = Obj1.GetContext
Obj1.Target = Obj1.RunMethod2("getSystemService", "input_method", "java.lang.String")
Obj1.RunMethod3("toggleSoftInput", 0, "java.lang.int", 0, "java.lang.int")
...

This works. When I click onto the lable I get an edittext with the old text editable with focus and keyboard.
After OK button from keyboard I save all and set it back to hidden disabled. No Problem.

But now the User want in one situation not back, but jump in another edit field by default.
So I put a call to the edit function directly and it works, while the debugger is in my code as it should ...
but when the debugger left the last shown end sub and give back the control to OS in the edittext view, the keyboard is hidden.
It was visible as long it was under the control of my code, but than it is gone.

If the user than click into the edittext control or directly click on the lable text before, the keyboard is shown correct.

I think, that I have to fire an event and close my function. Than let the OS call the edit routine for the second field.

But how to fire a click event by program ?

The code is a litte big, but I will offer it:

B4X:
Sub EditFeldopen( nLeft As Int, nTop As Int, nWidth As Int ) ' open the edit text control
   Dim nHeight As Int : nHeight = 60
   
   IsInEditMode = True ' steuert z.b. Activity_KeyPress
   
   ' Platz für Ränder machen 
   nLeft    = nLeft-5
   nTop    = nTop-5
   nWidth = nWidth+10
   ' zuerst Keyboard ausschalten
   
   Log("EditFeldOpen - hide KeyBoard")
   
   Dim p As Phone
   p.HideKeyboard(Activity)
   
   DoEvents
      
   Log("EditFeldOpen - request Feld")
   
   panEditMode.Color = Colors.ARGB(100,105,105,105) ' durchscheinend, Disabled Gray
   ' 150 ist Klaus zu grau ...
   
   ' Panel sichtbar machen und Feld anpassen
   panEditMode.SetLayout(0,0,activity.Width, activity.Height)
   'EditFeld.SetLayout( nLeft , nTop, nWidth, nHeight )
   EditFeld.Left = nLeft
   EditFeld.Top = nTop
   EditFeld.Width = nWidth
   'EditFeld.Height = nHeight ' ist schon im Designer vordefiniert.

   panEditMode.BringToFront         ' ganz nach oben   
   panEditMode.Visible = True         ' sichtbar machen
   panEditMode.Enabled = True         ' editierbar machen

   EditFeld.BringToFront         ' ganz nach oben   
   EditFeld.Visible = True         ' sichtbar machen
   EditFeld.Enabled = True         ' editierbar machen
   EditFeld.RequestFocus
   
   Log("EditFeldOpen - KeyBoard anfordern")   
   ' Keyboard umschalten, da es vorher aus war, geht es nun an.
'   HBFUNK.KeyBoardSwitch

   DoEvents
   
   Log("panAnzeige.top= " & panAnzeige.Top & " EditFeld.top= " & EditFeld.top )
   
   Dim Obj1 As Reflector
   Obj1.Target = Obj1.GetContext
   Obj1.Target = Obj1.RunMethod2("getSystemService", "input_method", "java.lang.String")
   Obj1.RunMethod3("toggleSoftInput", 0, "java.lang.int", 0, "java.lang.int")
      
   Log("panAnzeige.top= " & panAnzeige.Top & " EditFeld.top= " & EditFeld.top )

   DoEvents
   
   editfeld.SelectionStart = editfeld.Text.Length
   
   Log("EditFeldOpen Ende")   
   
End Sub

Sub EditFeldclose ' close and save ...

Log("EditFeldClose - Start")   

   Dim sFehler As String      : sFehler = "" ' "" ist kein Fehler
   Dim sFehlerTitel As String : sFehlerTitel = "Fehler"
   Dim sNow As String         : sNow = HBFUNK.date
   Dim sTxt As String
   Dim nInt As Int
   Dim nFloat As Float
   Dim p As Phone

   p.HideKeyboard(Activity)
   DoEvents
      
   editFeld.SendToBack
   EditFeld.Visible = False
   EditFeld.Enabled = False
'   EditFeld.SetLayout(0,0,0,0)
   EditFeld.Left = 0
   EditFeld.Top = 0      
   EditFeld.Width = 0      
   panEditMode.SetLayout(0,0,0,0)
   panEditMode.SendToBack
   panEditMode.Visible = False
   panEditMode.Enabled = False
   
   IsInEditMode = False ' steuert z.b. Activity_KeyPress
   
   DoEvents
   
Log("EditFeldClose - Feld verstecken")      
Log("EditFeldClose - Speichern nach ... " & oViewInEditMode)   
   
   If oViewInEditMode.EqualsIgnoreCase("StandNeu") Then 

      Dim nWert As Double
      If editFeld.Text="" Then
         nWert = 0
      Else   
         nWert = editFeld.Text
      End If   
      If PlausiAbleseStandNeu(nWert) Then 
         Try
            main.SQL1.ExecNonQuery( "UPDATE GE Set StandNeu = " & nWert & ", AbleseDat = '" & sNow & "' WHERE sMiGeNr = '" & oGE.sMiGeNr & "'" )
            oGE.StandNeu = nWert
            oGE.Ablesedat = sNow
            lblAbleseDat.Text   = sNow
            lblStandNeu.Text = ALLG.NumberFormatFloatRechts( nWert, 3 )      ' hier auch 0,000 anzeigen
            lblStandNeu.BringToFront
            Log("EditFeldClose - OK, neuer Wert in Feld ... " & oViewInEditMode)   
            If Plausi_CheckZahl_noetig Then
               If oGE.KZahl = "" Then
                  DoEvents
                  If MAIN.IsAutoEditStichtagswert Then

****> here I need to create an event "Click on lblCheckZahlZeile"

                     lblCheckZahlZeile_Click
                  Else   
                     Msgbox("Bitte Checkzahl eingeben","Checkzahl")
                  End If   
                  DoEvents
                  Log("EditFeldClose - OK, wechsel zu KZahl Eingabe")   
               Else
                  Plausi_CheckZahl_OK( True ) ' Eingabe muss möglich sein !
               End If
            End If   
         Catch 
            sFehler = "Stichtagswert konnte nicht gespeichert werden."
         End Try
      End If   
      
   Else If oViewInEditMode.EqualsIgnoreCase("StandAkt") Then 
   
      Dim nWert As Double
      If editFeld.Text="" Then
         nWert = 0
      Else   
         nWert = editFeld.Text
      End If   
      If PlausiAbleseStandAktuell(nWert) Then 
         Try
            main.SQL1.ExecNonQuery( "UPDATE GE Set StandAkt = " & nWert & ", AbleseDat = '" & sNow & "' WHERE sMiGeNr = '" & oGE.sMiGeNr & "'" )
            oGE.StandAkt = nWert
            oGE.Ablesedat = sNow
            lblAbleseDat.Text   = sNow
            If nWert > 0 Then
               lblStandAkt.Text = ALLG.NumberFormatFloatRechts( nWert, 3 )      
            Else   
               lblStandAkt.Text = ""
            End If 
            lblStandAkt.BringToFront
         Catch 
            sFehler = "Aktueller Wert konnte nicht gespeichert werden."
         End Try
      End If    
      
   Else If oViewInEditMode.EqualsIgnoreCase("KeyFab") Then 
   
      Dim nWert As Double
      If editFeld.Text="" Then
         nWert = 0
      Else   
         nWert = editFeld.Text
      End If   
      Try
         main.SQL1.ExecNonQuery( "UPDATE GE Set KeyFab = " & nWert & " WHERE sMiGeNr = '" & oGE.sMiGeNr & "'" )
         oGE.KeyFab = nWert
         If nWert > 0 Then
            lblKeyFab.Text = ALLG.NumberFormatIntRechts( nWert )      
         Else   
             lblKeyFab.Text = ""
         End If 
         lblKeyFab.BringToFront
      Catch 
         sFehler = "Fabrikats-Nr. konnte nicht gespeichert werden."
      End Try
      
   Else If oViewInEditMode.EqualsIgnoreCase("KZahl") Then
   
      ' die CheckZahl Prüfung folgt noch, hier nur das gröbste
      Try
         nInt = EditFeld.Text
         sTxt = NumberFormat2(nInt,4,0,0,False) ' 4 Stellen mit führenden Nullen
         If sTxt.Length > 4 Then
            sFehler = "Checkzahl hat mehr als 4 Stellen"
            sFehlerTitel = "Eingabefehler"
         End If   
      Catch
         sFehler = "Checkzahl ist falsch"      
      End Try 
      
      If sFehler="" Then 
         Try
            main.SQL1.ExecNonQuery( "UPDATE GE Set KZahl = '" & sTxt & "' WHERE sMiGeNr = '" & oGE.sMiGeNr & "'" )
            oGE.KZahl = sTxt
            lblCheckZahlZeile.Text = sTxt & " "
            lblCheckZahlZeile.BringToFront
             Plausi_CheckZahl_OK( True ) ' Eingabe muss möglich sein !
         Catch 
            sFehler = "CheckZahl konnte nicht gespeichert werden."
         End Try
      End If   
   
   Else If oViewInEditMode.EqualsIgnoreCase("GeraeteNr") Then

      Try
         main.SQL1.ExecNonQuery( "UPDATE GE Set GeraeteNr = '" & EditFeld.Text & "' WHERE sMiGeNr = '" & oGE.sMiGeNr & "'" )
         oGE.GeraeteNr = EditFeld.Text.Trim
          lblGeNrZeile.Text = " " & oGE.GeraeteNr
         lblGeNrZeile.BringToFront
      Catch 
         sFehler = "Geräte-Nr konnte nicht gespeichert werden."
      End Try

   Else If oViewInEditMode.EqualsIgnoreCase("Raum") Then

      Try
         main.SQL1.ExecNonQuery( "UPDATE GE Set Raum = '" & EditFeld.Text & "' WHERE sMiGeNr = '" & oGE.sMiGeNr & "'" )
         oGE.Raum = EditFeld.Text.Trim
          lblRaumZeile.Text = " " & oGE.Raum
         lblRaumZeile.BringToFront
      Catch 
         sFehler = "Geräte-Nr konnte nicht gespeichert werden."
      End Try
      
   ' else if ...
   
   End If
   
   If sFehler <> "" Then ' Fehler melden
      Log("EditFeldClose - Fehler : " & sFehler )
      Msgbox(sFehler,"Fehler")
   End If   
   
End Sub
 
Last edited:
Upvote 0
Top