Android Question Problem with altered B4XPreferencesDialog.b4xlib

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Have an altered B4XPreferencesDialog.b4xlib that has always worked perfectly fine (for several years), but now I got a problem when clicking a numeric text box:

Error occurred on line: 0 (B4XFloatTextField)
java.lang.Exception: Sub b4xfloattextfield1_focuschanged signature does not match expected signature.
public static anywheresoftware.b4a.pc.RemoteObject b4a.exampleljjll.preferencesdialog_subs_0._b4xfloattextfield1_focuschanged(anywheresoftware.b4a.pc.RemoteObject,anywheresoftware.b4a.pc.RemoteObject,anywheresoftware.b4a.pc.RemoteObject) throws java.lang.Exception
class anywheresoftware.b4a.pc.RemoteObject, class anywheresoftware.b4a.pc.RemoteObject,

I attach the file with the altered B4XPreferencesDialog.

This is how it is used in a B4X page class:

B4X:
Private Sub PrefDialog_IsValid(TempData As Map) As Boolean
    
    Dim number As Int = TempData.GetDefault("NumberToValidate", 0)
    
    If number < 10 Or number > 20 Then
        prefdialog.ScrollToItemWithError("NumberToValidate")
        Return False
    End If
    
    Return True
    
End Sub

'-------------------------------------------------------------------------------------------------------------
'Note here we have vTextField from Preferences dialog library as XUIViews library was changed to supply this!!
'-------------------------------------------------------------------------------------------------------------
Private Sub PrefDialog_TextFieldClicked(vTextField As B4XView)
    
    'vTextField.Tag will hold an Int array:
    'at arr(0): Enums.eEditText.PreferencesDialogTextField(34)
    'at arr(1): Type tPreferenceDialogItem (iText ,iDate ,iColor, iNumber, iDecimalNumber, iMultilineText etc.)
    'Dim arr() As Int = vTextField.Tag
    'Log("PrefDialog_TextFieldClicked, vTextField.Tag: " & arr(0) & ", " & arr(1))
    
    '------------------------------------------------------------------------------
    'this is needed to get a new text field if the keyboard was already visible
    'note clicking in the same text field won't trigger this event, so that is good
    '------------------------------------------------------------------------------
    cMP.HideKeyboard
    
    'this is used to put the keyboard top or bottom, not to cover the vTextField
    '---------------------------------------------------------------------------
    Dim iYPos As Int = vTextField.Parent.Parent.Parent.Top
    Dim iScrollPosY As Int = prefdialog.CustomListView1.sv.ScrollViewOffsetY
    Dim iYPosReal As Int = iYPos - iScrollPosY
    
    vSelectedTextField = vTextField
    
    SetOptionsCustomKeyboard(vTextField)
    
    cMP.iFocussedEditText = Enums.eEditText.PreferencesDialogTextField
    cMP.SetKeyboard(vTextField, iYPosReal, False)
    
End Sub

Any assistance to solve this would be greatly appreciated.

RBS
 

Attachments

  • PreferencesDialog.bas
    36.6 KB · Views: 10

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Thanks, I did have a look at and changed that, but then there were other errors.
Will look at it again and I guess that must be the trouble.

RBS
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
In your custom B4XPreferencesDialog you have:
B4X:
Sub b4xfloattextfield1_FocusChanged(vTextField As B4XView, bHasFocus As Boolean)
[/CODICE]
but the signature of the FocusChanged event of B4XFloatTextField is so:
B4X:
Private Sub b4xfloattextfield1_FocusChanged (HasFocus As Boolean)
How does the Private Sub PrefDialog_TextFieldClicked in the B4X page know what textfield was clicked?
Or otherwise how does Sub b4xfloattextfield1_FocusChanged(bHasFocus As Boolean) in the Preference dialog know
what text field was clicked, do pass it to the B4X page?

RBS
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
How does the Private Sub PrefDialog_TextFieldClicked in the B4X page know what textfield was clicked?
Or otherwise how does Sub b4xfloattextfield1_FocusChanged(bHasFocus As Boolean) in the Preference dialog know
what text field was clicked, do pass it to the B4X page?

RBS
Meant:
to pass it to the B4X page?

RBS
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
How does the Private Sub PrefDialog_TextFieldClicked in the B4X page know what textfield was clicked?
General rule:

In a View event Sub, use the Sender object (it's a B4X keyword).
For example:
B4X:
If Sender Is EditText Then ...
Another example:
B4X:
If Sender Is EditText Then
   Dim ET As EditText = Sender
   If ET.Tag = "NameField" Then

In your specific case I don't know, I should look into it but I'm sleepy, it's 4:30 A.M. :confused::)
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
General rule:

In a View event Sub, use the Sender object (it's a B4X keyword).
For example:
B4X:
If Sender Is EditText Then ...
Another example:
B4X:
If Sender Is EditText Then
   Dim ET As EditText = Sender
   If ET.Tag = "NameField" Then

In your specific case I don't know, I should look into it but I'm sleepy, it's 4:30 A.M. :confused::)
All solved now.
I overlooked the fact that the XUI Views.b4xlib was changed as well, although I did put that in the posted B4X code.
It was messed up when I upgraded to B4A 13.5 some weeks ago, altering XUI Views.b4xlib.

This was the change in the B4XFloatTextField.bas in the XUI Views.b4xlib:

B4X:
'This was altered to supply the mTextField to B4XPreferencesDialog.b4xlib
'------------------------------------------------------------------------
Private Sub tf_FocusChanged (HasFocus As Boolean)
    Focused = HasFocus
    UpdateLabel(mTextField.Text, True)
    If xui.SubExists(mCallBack, mEventName & "_FocusChanged", 1) Then
        If LastSwitchTextFieldTime + 100 < DateTime.Now Then
            CallSubDelayed3(mCallBack, mEventName & "_FocusChanged", mTextField, Focused)
        End If
    End If
End Sub

'Private Sub tf_FocusChanged (HasFocus As Boolean)
    'Focused = HasFocus
    'UpdateLabel(mTextField.Text, True)
    'If xui.SubExists(mCallBack, mEventName & "_FocusChanged", 1) Then
        'If LastSwitchTextFieldTime + 100 < DateTime.Now Then
            'CallSubDelayed2(mCallBack, mEventName & "_FocusChanged", Focused)
        'End If
    'End If
'End Sub

Then this code in the B4XPreferencesDialog.b4xlib will work all fine:

B4X:
'At the top:
#Event: FocusChanged(vTextField As B4XView, bHasFocus As Boolean)

Sub b4xfloattextfield1_FocusChanged(vTextField As B4XView, bHasFocus As Boolean)

    If bHasFocus Then
        If mEventName <> "" And xui.SubExists(mCallback, mEventName  & "_TextFieldClicked", 1) Then
            'vTextField.Tag = "45"
            CallSub2(mCallback, mEventName & "_TextFieldClicked", vTextField)
        End If
    End If
    
End Sub

Then in the B4X Page we have this code (posted already) that works now fine;

B4X:
'-------------------------------------------------------------------------------------------------------------
'Note here we have vTextField from Preferences dialog library as XUIViews library was changed to supply this!!
'-------------------------------------------------------------------------------------------------------------
Private Sub PrefDialog_TextFieldClicked(vTextField As B4XView)
    
    'vTextField.Tag will hold an Int array:
    'at arr(0): Enums.eEditText.PreferencesDialogTextField(34)
    'at arr(1): Type tPreferenceDialogItem (iText ,iDate ,iColor, iNumber, iDecimalNumber, iMultilineText etc.)
    'Dim arr() As Int = vTextField.Tag
    'Log("PrefDialog_TextFieldClicked, vTextField.Tag: " & arr(0) & ", " & arr(1))
    
    '------------------------------------------------------------------------------
    'this is needed to get a new text field if the keyboard was already visible
    'note clicking in the same text field won't trigger this event, so that is good
    '------------------------------------------------------------------------------
    cMP.HideKeyboard
    
    'this is used to put the keyboard top or bottom, not to cover the vTextField
    '---------------------------------------------------------------------------
    Dim iYPos As Int = vTextField.Parent.Parent.Parent.Top
    Dim iScrollPosY As Int = prefdialog.CustomListView1.sv.ScrollViewOffsetY
    Dim iYPosReal As Int = iYPos - iScrollPosY
    
    vSelectedTextField = vTextField
    
    SetOptionsCustomKeyboard(vTextField)
    
    cMP.iFocussedEditText = Enums.eEditText.PreferencesDialogTextField
    cMP.SetKeyboard(vTextField, iYPosReal, False)
    
End Sub

My mistake was not looking at the comment at the top of Private Sub PrefDialog_TextFieldClicked!

RBS
 
Upvote 0
Top