Sub Test2(InputValue As Int) As ResumableSub
Dim pnlWidth As Int = Min(GetDeviceLayoutValues.Width, GetDeviceLayoutValues.Height) - 32dip 'Allow margins either side
Dim tfHeight As Int = 40dip
Dim pnlHeight As Int = tfHeight + 32dip 'Can be adjusted to achieve a more compressed layout if needed
Dim pnl As Panel 'Panel can be used to indicate invalid input by adding code for tf events and setting panel color or border
pnl.Initialize("")
Dim tf As EditText
tf.Initialize("")
tf.TextSize = 18
tf.InputType = tf.INPUT_TYPE_NUMBERS 'Numeric keyboard
tf.Hint = "999"
tf.Gravity = Bit.Or(Gravity.LEFT, Gravity.CENTER_VERTICAL)
If InputValue > 0 Then tf.Text = NumberFormat(InputValue, 1, 0) 'If current value is zero, keep tf.text empty to show hint
Dim id As CustomLayoutDialog
Dim sf As Object = id.ShowAsync("Test2", "Ok", "Cancel", "", Null, True)
id.SetSize(pnlWidth + 32dip, pnlHeight + 128dip) 'Add back the width margins, plus 64dip for icon/title plus 64dip for buttons
Wait For (sf) Dialog_Ready (dp As Panel)
dp.AddView(pnl, 0, 0, pnlWidth, pnlHeight)
pnl.AddView(tf, 8dip, pnlHeight - tfHeight, pnlWidth - 16dip, tfHeight)
tf.RequestFocus 'Start with cursor in text field
Wait For (sf) Dialog_Result(Result As Int)
Dim OutputValue As Int = InputValue
If Result = DialogResponse.POSITIVE Then
If tf.Text.Length = 0 Then
'Have seen issues with string->int when field is empty - avoid the issues.
OutputValue = 0
Else
OutputValue = tf.Text
End If
End If
tf.Enabled = False 'Close the keyboard
Return OutputValue
End Sub