Android Question [Solved] How to set the SingleLine to the TextField of B4XInputTemplate Dialog?

asales

Expert
Licensed User
Longtime User
I tried this 2 codes, without success:
B4X:
input.TextField1.As(EditText).SingleLine = True
B4X:
Dim et As EditText = input.TextField1
et.SingleLine = True
Both raises the same error:
B4X:
java.lang.NullPointerException: Attempt to invoke virtual method 'anywheresoftware.b4a.BA$IterableList anywheresoftware.b4a.objects.B4XViewWrapper.GetAllViewsRecursive()' on a null object reference
Thanks in advance for any help.
 
Solution
test text} and Wrap
B4X:
    Dim input As B4XInputTemplate
    input.Initialize
    Dim rs As ResumableSub = dialog.ShowTemplate(input, "OK", "", "CANCEL")
    input.lblTitle.Text = "Text:"
    input.TextField1.As(EditText).SingleLine = False
    input.TextField1.As(EditText).Wrap = True
    Wait For (rs) Complete (Result As Int)
    If Result = xui.DialogResponse_Positive Then
        dialog.Show($"${input.Text}"$, "OK", "", "")
    End If

walterf25

Expert
Licensed User
Longtime User
I tried this 2 codes, without success:
B4X:
input.TextField1.As(EditText).SingleLine = True
B4X:
Dim et As EditText = input.TextField1
et.SingleLine = True
Both raises the same error:
B4X:
java.lang.NullPointerException: Attempt to invoke virtual method 'anywheresoftware.b4a.BA$IterableList anywheresoftware.b4a.objects.B4XViewWrapper.GetAllViewsRecursive()' on a null object reference
Thanks in advance for any help.
Based on the error, seems the problem is somewhere else, are you looping through your views somewhere else in your code, unless that's what the internal is doing somehow.
 
Upvote 0

asales

Expert
Licensed User
Longtime User
Changed this example from @Erel, with the code below, and get the same error:
B4X:
Private Sub btnSingleLine_Click
    Dim input As B4XInputTemplate
    input.Initialize
    input.lblTitle.Text = "SingleLine:"
    
'set singleline
'    input.TextField1.As(EditText).SingleLine = True
'OR
'    Dim et As EditText = input.TextField1
'    et.SingleLine = True
    
    Wait For (dialog.ShowTemplate(input, "OK", "", "CANCEL")) Complete (Result As Int)
    If Result = xui.DialogResponse_Positive Then
        Dim res As Int = input.Text
        Log(res)
    End If   
End Sub
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
Changed this example from @Erel, with the code below, and get the same error:
B4X:
Private Sub btnSingleLine_Click
    Dim input As B4XInputTemplate
    input.Initialize
    input.lblTitle.Text = "SingleLine:"
   
'set singleline
'    input.TextField1.As(EditText).SingleLine = True
'OR
'    Dim et As EditText = input.TextField1
'    et.SingleLine = True
   
    Wait For (dialog.ShowTemplate(input, "OK", "", "CANCEL")) Complete (Result As Int)
    If Result = xui.DialogResponse_Positive Then
        Dim res As Int = input.Text
        Log(res)
    End If  
End Sub
Then the problem is somewhere else.

Walter
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
test:
B4X:
    Dim input As B4XInputTemplate
    input.Initialize
    Dim rs As ResumableSub = dialog.ShowTemplate(input, "OK", "", "CANCEL")
    input.lblTitle.Text = "Whole Positive:"
    input.ConfigureForNumbers(False, False)
    input.TextField1.As(EditText).SingleLine = True
    Wait For (rs) Complete (Result As Int)
    If Result = xui.DialogResponse_Positive Then
        Dim res As Int = input.Text 'no need to check with IsNumber
        dialog.Show($"2 * $1.2{res} = $1.2{2 * res}"$, "OK", "", "")
    End If
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
test text} and Wrap
B4X:
    Dim input As B4XInputTemplate
    input.Initialize
    Dim rs As ResumableSub = dialog.ShowTemplate(input, "OK", "", "CANCEL")
    input.lblTitle.Text = "Text:"
    input.TextField1.As(EditText).SingleLine = False
    input.TextField1.As(EditText).Wrap = True
    Wait For (rs) Complete (Result As Int)
    If Result = xui.DialogResponse_Positive Then
        dialog.Show($"${input.Text}"$, "OK", "", "")
    End If
 
Upvote 2
Solution

asales

Expert
Licensed User
Longtime User
test text} and Wrap
B4X:
    Dim input As B4XInputTemplate
    input.Initialize
    Dim rs As ResumableSub = dialog.ShowTemplate(input, "OK", "", "CANCEL")
    input.lblTitle.Text = "Text:"
    input.TextField1.As(EditText).SingleLine = False
    input.TextField1.As(EditText).Wrap = True
    Wait For (rs) Complete (Result As Int)
    If Result = xui.DialogResponse_Positive Then
        dialog.Show($"${input.Text}"$, "OK", "", "")
    End If
Thanks @TILogistic! It worked!
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Both raises the same error:
Your original code like the below should work. You did not need to set the textfield1.singleline to true because it is true by default when the internal layout of B4XInputTemplate is loaded. I tried it on Erel' s example and it worked every time. Am I misunderstanding your thread.
B4X:
private Sub btnSingleLine_Click
    Dim input As B4XInputTemplate
    input.Initialize
    input.lblTitle.Text = "SingleLine:"  
    Wait For (dialog.ShowTemplate(input, "OK", "", "CANCEL")) Complete (Result As Int)
    If Result = xui.DialogResponse_Positive Then
        Dim res As Int = input.Text
        Log(res)
    End If   
End Sub
 
Upvote 0
Top