Android Question Resolved: B4XDialog input keyboard set

padvou

Active Member
Licensed User
Longtime User
Hello,
I'm using the following code:
B4X:
Dim input As B4XInputTemplate
        input.Initialize
        Dialog.Initialize(Root)
        Dialog.Title="Please enter your data"
        input.lblTitle.Text = "String containing only numbers:"
        input.TextField1.RequestFocus
        Wait For (Dialog.ShowTemplate(input, "Yes", "", "No")) Complete (Result As Int)
        ...
The problem is that if I use
B4X:
input.ConfigureForNumbers(False,False)
, if the entered value starts with 0, then the dialog disables the "Yes" key.
How could I work around this and still keep the keyboard showing only numbers and the minus sign?
Thank you.
 
Solution
Ok, here's what I came up with:

B4X:
Dim p As B4XView = xui.CreatePanel("")
        p.SetLayoutAnimated(0, 0, 0, 300dip, 150dip)
        p.LoadLayout("CustomerDataDialog")
        If Dialog.IsInitialized = False Then Dialog.Initialize(Root)
        Dialog.Title="Please enter the required data first"
        Dim t1 As EditText
        t1=etFirst.TextField
        If t1.IsInitialized = False Then t1.Initialize("t1")
        IMA.SetCustomFilter(t1,t1.INPUT_TYPE_NUMBERS,"0123456789")
        Dim t2 As EditText
        t2=etSecond.TextField
        If t2.IsInitialized = False Then t2.Initialize("t2")
        IMA.SetCustomFilter(t2,t2.INPUT_TYPE_NUMBERS,"0123456789-")
        Dialog.PutAtTop = True 'put the dialog at the top of the screen...

padvou

Active Member
Licensed User
Longtime User
The regex patten for this configuration is:
B4X:
"^(0|[1-9]\d*)$"
You want to change it to:
B4X:
input.RegexPattern = "\d+"
ok, this worked accepting the leading 0. But the "-" sign is disabled in the keyboard.
So I tried:
B4X:
input.ConfigureForNumbers(False,True)
input.RegexPattern = "\d+-"
It enabled the button, but it only types "." (the dot) and not the "-" minus sign.
What I'm trying to be able to write, to be more specific, is a pattern like this: dd-dddd where d is digit. So, 2 digits, a minus sign and four digits.
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
There are two different features here:
1. The keyboard input type.
2. The regex validation pattern.
There isn't any relation between the two.

For your case you will need to set the keyboard input type to text and use a regex pattern that will validate your string, which isn't a number.
The regex should be: "^\d{2}-\d{4}$"
 
Upvote 0

padvou

Active Member
Licensed User
Longtime User
There are two different features here:
1. The keyboard input type.
2. The regex validation pattern.
There isn't any relation between the two.

For your case you will need to set the keyboard input type to text and use a regex pattern that will validate your string, which isn't a number.
The regex should be: "^\d{2}-\d{4}$"
Since keyboard input type text is what I'm trying to avoid, because the user needs only the numbers and minus sign, is it possible to make the input textbox like __-____, so that the minus sign is already there and the user just types the numbers?
 
Upvote 0

padvou

Active Member
Licensed User
Longtime User
Ok, here's what I came up with:

B4X:
Dim p As B4XView = xui.CreatePanel("")
        p.SetLayoutAnimated(0, 0, 0, 300dip, 150dip)
        p.LoadLayout("CustomerDataDialog")
        If Dialog.IsInitialized = False Then Dialog.Initialize(Root)
        Dialog.Title="Please enter the required data first"
        Dim t1 As EditText
        t1=etFirst.TextField
        If t1.IsInitialized = False Then t1.Initialize("t1")
        IMA.SetCustomFilter(t1,t1.INPUT_TYPE_NUMBERS,"0123456789")
        Dim t2 As EditText
        t2=etSecond.TextField
        If t2.IsInitialized = False Then t2.Initialize("t2")
        IMA.SetCustomFilter(t2,t2.INPUT_TYPE_NUMBERS,"0123456789-")
        Dialog.PutAtTop = True 'put the dialog at the top of the screen
        Wait For (Dialog.ShowCustom(p, "OK", "", "CANCEL")) Complete (Result As Int)

but now, the dialog title is too long to fit in the dialog title area. I tried to set it, but I get an error that it's not initialized
 
Upvote 0

padvou

Active Member
Licensed User
Longtime User
Ok, here's what I came up with:

B4X:
Dim p As B4XView = xui.CreatePanel("")
        p.SetLayoutAnimated(0, 0, 0, 300dip, 150dip)
        p.LoadLayout("CustomerDataDialog")
        If Dialog.IsInitialized = False Then Dialog.Initialize(Root)
        Dialog.Title="Please enter the required data first"
        Dim t1 As EditText
        t1=etFirst.TextField
        If t1.IsInitialized = False Then t1.Initialize("t1")
        IMA.SetCustomFilter(t1,t1.INPUT_TYPE_NUMBERS,"0123456789")
        Dim t2 As EditText
        t2=etSecond.TextField
        If t2.IsInitialized = False Then t2.Initialize("t2")
        IMA.SetCustomFilter(t2,t2.INPUT_TYPE_NUMBERS,"0123456789-")
        Dialog.PutAtTop = True 'put the dialog at the top of the screen
        Wait For (Dialog.ShowCustom(p, "OK", "", "CANCEL")) Complete (Result As Int)

but now, the dialog title is too long to fit in the dialog title area. I tried to set it, but I get an error that it's not initialized

resolved here: https://www.b4x.com/android/forum/t...ore-the-dialog-is-not-showing.108657/#content
 
Upvote 0
Solution
Top