Android Question B4XInputTemplate ENTER behaviour

advansis

Active Member
Licensed User
Longtime User
Hi, all.
I use an InputTemplate to insert a multiline text.
When I press the New-Line (Enter) button on IME the dialog closes (even if a new line is added to the result).
I just would like to add new lines to the string... any ideas? Thanks a lot

This is my code...

Settings:
Dim dlg As B4XDialog
Dim tinput As B4XInputTemplate

    [...]

    Sub AskText(root As B4XView,caption As String,value As String,minlen As Int) As ResumableSub
    If dlg.IsInitialized=False Then dlg.Initialize(root)
    If tinput.IsInitialized=False Then tinput.Initialize
    tinput.mBase.Height=40%y
    tinput.lblTitle.Text=caption
    Dim ef As EditText=tinput.TextField1
    ef.SingleLine=False
    ef.Height=35%y
    ef.Gravity=Bit.Or(Gravity.TOP,Gravity.LEFT)
    ef.InputType=Bit.Or(ef.INPUT_TYPE_TEXT,0x20000) ' TYPE_TEXT_FLAG_MULTI_LINE + TYPE_CLASS_TEXT
    ef.ForceDoneButton = False
    tinput.Text=value
    wait for (dlg.ShowTemplate(tinput,"OK","","Cancel")) Complete (res As Int)
    If res=xui.DialogResponse_Positive Then
        Return tinput.text
    End If
    Return ""
End Sub
 

advansis

Active Member
Licensed User
Longtime User
Thanks Erel, I did this trick and seems to work, hope will be useful to others...

Consider:
1) Is not possible to put "" in [Yes] (=first button) caption
2) SetButtonState(xui.DialogResponse_Positive,false) seems not no work, so need to hide
3) I only need 2 buttons, so can ignore the first one
4) regex validation can block button press

Trick:
tinput.RegexPattern =".{100000,}" ' Very long (or other regex never matching) to disable OK button

Dim rs As ResumableSub=dlg.ShowTemplate(tinput,"-","OK","Cancel")
dlg.GetButton(xui.DialogResponse_Positive).visible= False
wait for (rs) Complete (res As Int)

If res=xui.DialogResponse_Negative Then ' '-> as if it was DialogResponse_Positive

*WISH* It would be very useful to provide callbacks for Text-Changing, Text-Enter in B4XInputTemplate and Button-Click in Dialog
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…