Android Question [B4X] Different behavior modifying buttons in B4XDialog between B4j and B4A

MrKim

Well-Known Member
Licensed User
Longtime User
I started with this:
B4X:
Dim B As B4XView = KimsDlg.GetButton(xui.DialogResponse_Positive)
B.SetLayoutAnimated(0, B.Parent.Width * .02, B.Parent.Height - (B.Height + 10dip), B.Parent.Width * .3, B.Height)
Dim B As B4XView = KimsDlg.GetButton(xui.DialogResponse_Negative)
B.SetLayoutAnimated(0, B.Parent.Width * .35, B.Parent.Height - (B.Height + 10dip), B.Parent.Width * .3, B.Height)
Dim B As B4XView = KimsDlg.GetButton(xui.DialogResponse_Cancel)
B.SetLayoutAnimated(0, B.Parent.Width * .68, B.Parent.Height - (B.Height + 10dip), B.Parent.Width * .3, B.Height)
To move the buttons.
Unfortunately the first time I didn't need on of the buttons it failed. Evidently the buttons are not created if they are not needed.
So I did this:
B4X:
    Dim B As B4XView = KimsDlg.GetButton(xui.DialogResponse_Positive)
    If B.IsInitialized Then    B.SetLayoutAnimated(0, B.Parent.Width * .02, B.Parent.Height - (B.Height + 10dip), B.Parent.Width * .3, B.Height)
    Dim B As B4XView = KimsDlg.GetButton(xui.DialogResponse_Negative)
    If B.IsInitialized Then    B.SetLayoutAnimated(0, B.Parent.Width * .35, B.Parent.Height - (B.Height + 10dip), B.Parent.Width * .3, B.Height)
    Dim B As B4XView = KimsDlg.GetButton(xui.DialogResponse_Cancel)
    If B.IsInitialized Then    B.SetLayoutAnimated(0, B.Parent.Width * .68, B.Parent.Height - (B.Height + 10dip), B.Parent.Width * .3, B.Height)
Which worked great in B4J, unfortunately it fails in B4A in the B4XDialog, not in my code:
B4X:
Error occurred on line: 214 (B4XDialog)
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.Object.equals(java.lang.Object)' on a null object reference
So, Ultimately I just tested the length of the text for each button, probably what I should have done in the first place.
B4X:
    If Y.Length > 0 Then
        Dim B As B4XView = KimsDlg.GetButton(xui.DialogResponse_Positive)
        B.SetLayoutAnimated(0, B.Parent.Width * .02, B.Parent.Height - (B.Height + 10dip), B.Parent.Width * .3, B.Height)
    End If
    If N.Length > 0 Then
        Dim B As B4XView = KimsDlg.GetButton(xui.DialogResponse_Negative)
        B.SetLayoutAnimated(0, B.Parent.Width * .35, B.Parent.Height - (B.Height + 10dip), B.Parent.Width * .3, B.Height)
    End If
    If Can.Length > 0 Then
        Dim B As B4XView = KimsDlg.GetButton(xui.DialogResponse_Cancel)
        If B.IsInitialized Then    B.SetLayoutAnimated(0, B.Parent.Width * .68, B.Parent.Height - (B.Height + 10dip), B.Parent.Width * .3, B.Height)
    End If
Hope this helps someone.
 
Top