Android Question Modified Edittext for HH:mm entry

harinder

Active Member
Licensed User
Longtime User
How can I modify entry into edittext so that I can allow entry of 3000 hrs and 50 mins to be entered as 3000:50. To be more precise, hours on left side of colon can be any positive number >=0, but minutes on right side of colon < 60.
 

Mahares

Expert
Licensed User
Longtime User
Maybe something like this using cross platform views

B4X:
Private edt As EditText   
    Private InputTemplate As B4XInputTemplate    'need XUI Views Lib
    Private XUI As XUI   'need XUI lib
    Private Dialog As B4XDialog
    Private Base As B4XView

InputTemplate.Initialize
    Base = Activity
    Dialog.Initialize (Base)
    InputTemplate.lblTitle.Text = "Enter time (HHHH:MM)"  'any number of hours
    InputTemplate.RegexPattern = "([0-9]+):[0-5][0-9]$"
    Wait For (Dialog.ShowTemplate(InputTemplate, "OK", "", "CANCEL")) Complete (Result As Int)
    If Result = XUI.DialogResponse_Positive Then
        edt.Text = InputTemplate.Text
    End If
 
Upvote 0

harinder

Active Member
Licensed User
Longtime User
Maybe something like this using cross platform views

B4X:
Private edt As EditText  
    Private InputTemplate As B4XInputTemplate    'need XUI Views Lib
    Private XUI As XUI   'need XUI lib
    Private Dialog As B4XDialog
    Private Base As B4XView

InputTemplate.Initialize
    Base = Activity
    Dialog.Initialize (Base)
    InputTemplate.lblTitle.Text = "Enter time (HHHH:MM)"  'any number of hours
    InputTemplate.RegexPattern = "([0-9]+):[0-5][0-9]$"
    Wait For (Dialog.ShowTemplate(InputTemplate, "OK", "", "CANCEL")) Complete (Result As Int)
    If Result = XUI.DialogResponse_Positive Then
        edt.Text = InputTemplate.Text
    End If
Wonderful..So Regex does the trick..Exactly what I was looking for..
 
Upvote 0
Top