Android Question numeric filtering or, an alternative? Maybe in text_changed preferrably?

bodycode

Member
Licensed User
Longtime User
I've been trying to get an answer here with various posts. But now maybe this post is articulated in a better way.

I would like to do the following. Unfortunately, no one was willing to actually show me the bit of code that would do this

  1. Click a button that immediately opens a NUMERIC-only dialog box AND numeric keyboard simultaneously (that is a pre-req, because no one wants to click something twice to get to a numeric keyboard, especially if it's submitted on google play, right?)
  2. Assign the input, to a double-type variable for calculations.
  3. Get the input checked for numeric-only, min and max value of numbers, AND to dis-allow an input starting with any input, that would not be a numeric.
  4. Ideally, have a completely filtered input, which only allows an input from 1 to 1000, disallowing a minus sign or any other starting value that will crash a try catch for numeric assign to a double-type variable.
I haven't been able to get this accomplished at all. I was told WHAT to use, but not how to do it. In addition, I've learned that any input that STARTS with the following is not a numeric. If input starts with a minus sign but nothing after, starts with a minus sign and zero, or, just a decimal, as well as a minus sign and zero, are not numeric. Therefore... that needs to be checked for, and, then the input needs to open again for the user to correct without being an error when assigning the input value to a double-type variable. Right? thanks in advance.

PS: It doesn't have to be a text_changed, it can be a dialog box, but, the keypad needs to open as soon as a button is pressed with one click, not two.

bodycode
 

Informatix

Expert
Licensed User
Longtime User
Sorry, I can't see where's the difficulty.
As I suggested, here's an example with BetterDialogs. I did nothing special. No complex algorithm, no trick. Just a simple test with IsNumber.
If you want to control exactly what's entered, create a custom dialog with a masked edittext and use its filter event.
 

Attachments

  • DecimalInput.zip
    6.1 KB · Views: 283
Upvote 0

TomA

Active Member
Licensed User
Longtime User
Actually, I think this is a relatively simple problem if you use the IME library - you can ensure that only the numeric keyboard shows, filter the input so it only accepts numbers (including - and . and leading 0), then do what you like if it is not numeric. I took the liberty of modifying one of the B4A sample programs (rather than write a specific example) - see the NumberOnly program included here) so that one field will only accept the filtered numeric input and test to ensure that it really is numeric (and does not contain something like more than one decimal). Check the code used for the EditText3 field. Also, you can control when the keyboard opens and closes. You can also change the filter that presently is set as "0123456789.-" to "0123456789" so the - and/or decimal cannot be entered.
 

Attachments

  • NumberOnly.zip
    11 KB · Views: 282
Last edited:
Upvote 0

bodycode

Member
Licensed User
Longtime User
Didn't see the attachment, thanks. I know there are no "tricks" and that it's pretty simple.:)

Thanks again.

Marsh

I've been trying to get an answer here with various posts. But now maybe this post is articulated in a better way.

I would like to do the following. Unfortunately, no one was willing to actually show me the bit of code that would do this

  1. Click a button that immediately opens a NUMERIC-only dialog box AND numeric keyboard simultaneously (that is a pre-req, because no one wants to click something twice to get to a numeric keyboard, especially if it's submitted on google play, right?)
  2. Assign the input, to a double-type variable for calculations.
  3. Get the input checked for numeric-only, min and max value of numbers, AND to dis-allow an input starting with any input, that would not be a numeric.
  4. Ideally, have a completely filtered input, which only allows an input from 1 to 1000, disallowing a minus sign or any other starting value that will crash a try catch for numeric assign to a double-type variable.
I haven't been able to get this accomplished at all. I was told WHAT to use, but not how to do it. In addition, I've learned that any input that STARTS with the following is not a numeric. If input starts with a minus sign but nothing after, starts with a minus sign and zero, or, just a decimal, as well as a minus sign and zero, are not numeric. Therefore... that needs to be checked for, and, then the input needs to open again for the user to correct without being an error when assigning the input value to a double-type variable. Right? thanks in advance.

PS: It doesn't have to be a text_changed, it can be a dialog box, but, the keypad needs to open as soon as a button is pressed with one click, not two.

bodycode
 
Upvote 0

bodycode

Member
Licensed User
Longtime User
Missed every single attachment Arghh! My fault. Thanks. Nice n' simple really.

I was wondering how the Sub Input_Validation (Answer As String, CompactAnswer As String) As String sub is called?

Is that sub part of the BetterDialogs library?

I've been trying to get an answer here with various posts. But now maybe this post is articulated in a better way.

I would like to do the following. Unfortunately, no one was willing to actually show me the bit of code that would do this

  1. Click a button that immediately opens a NUMERIC-only dialog box AND numeric keyboard simultaneously (that is a pre-req, because no one wants to click something twice to get to a numeric keyboard, especially if it's submitted on google play, right?)
  2. Assign the input, to a double-type variable for calculations.
  3. Get the input checked for numeric-only, min and max value of numbers, AND to dis-allow an input starting with any input, that would not be a numeric.
  4. Ideally, have a completely filtered input, which only allows an input from 1 to 1000, disallowing a minus sign or any other starting value that will crash a try catch for numeric assign to a double-type variable.
I haven't been able to get this accomplished at all. I was told WHAT to use, but not how to do it. In addition, I've learned that any input that STARTS with the following is not a numeric. If input starts with a minus sign but nothing after, starts with a minus sign and zero, or, just a decimal, as well as a minus sign and zero, are not numeric. Therefore... that needs to be checked for, and, then the input needs to open again for the user to correct without being an error when assigning the input value to a double-type variable. Right? thanks in advance.

PS: It doesn't have to be a text_changed, it can be a dialog box, but, the keypad needs to open as soon as a button is pressed with one click, not two.

bodycode



Sorry, I can't see where's the difficulty.
As I suggested, here's an example with BetterDialogs. I did nothing special. No complex algorithm, no trick. Just a simple test with IsNumber.
If you want to control exactly what's entered, create a custom dialog with a masked edittext and use its filter event.
 
Upvote 0

bodycode

Member
Licensed User
Longtime User
Thank you! This is good.


Actually, I think this is a relatively simple problem if you use the IME library - you can ensure that only the numeric keyboard shows, filter the input so it only accepts numbers (including - and . and leading 0), then do what you like if it is not numeric. I took the liberty of modifying one of the B4A sample programs (rather than write a specific example) - see the NumberOnly program included here) so that one field will only accept the filtered numeric input and test to ensure that it really is numeric (and does not contain something like more than one decimal). Check the code used for the EditText3 field. Also, you can control when the keyboard opens and closes. You can also change the filter that presently is set as "0123456789.-" to "0123456789" so the - and/or decimal cannot be entered.
Actually, I think this is a relatively simple problem if you use the IME library - you can ensure that only the numeric keyboard shows, filter the input so it only accepts numbers (including - and . and leading 0), then do what you like if it is not numeric. I took the liberty of modifying one of the B4A sample programs (rather than write a specific example) - see the NumberOnly program included here) so that one field will only accept the filtered numeric input and test to ensure that it really is numeric (and does not contain something like more than one decimal). Check the code used for the EditText3 field. Also, you can control when the keyboard opens and closes. You can also change the filter that presently is set as "0123456789.-" to "0123456789" so the - and/or decimal cannot be entered.
 
Upvote 0

bodycode

Member
Licensed User
Longtime User
I'm using Informatix's BetterDialogs to open a numeric keypad as soon as a textedit field is displayed without clicking it. Any way to do that with the IME library, but no betterdialogs?

For instance, have a button load a texteditfield sub, and have a dialog box open without a click on the textedit?



Actually, I think this is a relatively simple problem if you use the IME library - you can ensure that only the numeric keyboard shows, filter the input so it only accepts numbers (including - and . and leading 0), then do what you like if it is not numeric. I took the liberty of modifying one of the B4A sample programs (rather than write a specific example) - see the NumberOnly program included here) so that one field will only accept the filtered numeric input and test to ensure that it really is numeric (and does not contain something like more than one decimal). Check the code used for the EditText3 field. Also, you can control when the keyboard opens and closes. You can also change the filter that presently is set as "0123456789.-" to "0123456789" so the - and/or decimal cannot be entered.
 
Upvote 0

bodycode

Member
Licensed User
Longtime User
Can't figure out why this doesn't open a dialog box when I click the button? I'm really getting stumped here. I downloaded the example, however, I'd like to code from scratch and not just copy, paste and modify.

I have some miscellanious garbage in the file, but that shouldn't matter?

Thanks.


It is called when the user clicks on the Positive button and a validation sub has been declared with ValidationCallback.
 
Upvote 0

bodycode

Member
Licensed User
Longtime User
Steve, how does the code loop back to the input box when the input is not a number? I understand the concept of popping back up to the
beginning of a sub using the old basic. Is it the return keyword? If so, I see that there's also a text parameter? Is this a combined jump back to the beginning of the sub using Return, as well as text output? I'm confused.

Thanks


Sorry, I can't see where's the difficulty.
As I suggested, here's an example with BetterDialogs. I did nothing special. No complex algorithm, no trick. Just a simple test with IsNumber.
If you want to control exactly what's entered, create a custom dialog with a masked edittext and use its filter event.
 
Upvote 0

bodycode

Member
Licensed User
Longtime User
Who is Steve? I hope that he reads this thread or you're going to wait a long time... ;)

To run the same code until a condition is true, you have to use a Do...Loop (Beginner's Guide p237).
Sorry :(
 
Upvote 0

bodycode

Member
Licensed User
Longtime User
Informatix (I know, not Steve :( ), I can't figure out where I'm going wrong to try to use masked input in your BetterDialogs. Here's the code. Upon compilation, it errors. I know that I need to create a statement with an equals sign, with your Format parameter?


Sub NutritLabelWeightDialogBoxSub 'Dialog box code called from button.
Dim DialogBoxParams As BD_InputBoxParams
DialogBoxParams.Initialize
DialogBoxParams.Question = "<I> Enter food weight</I>"
DialogBoxParams.QuestionTextSize = 22
DialogBoxParams.SpaceBetween = 4dip
DialogBoxParams.InputTextSize = 24
DialogBoxParams.InputType = DialogBoxParams.INPUT_TYPE_DECIMAL_NUMBERS
DialogBoxParams.Gravity = Gravity.CENTER_VERTICAL + Gravity.CENTER_HORIZONTAL
DialogBoxParams.ValidationCallback = "NutritLabelWeightNumericValidation"
DialogBoxParams.Format("####.###")

Dim DialogButtonParameters As Int = NutritLabelWeightDialogBox.InputBox("Number input", DialogBoxParams, "OK", "Cancel", "", Null)

If DialogButtonParameters = DialogResponse.POSITIVE Then
'Log(DialogBoxParams.Answer)
'Label2.Text = DialogBoxParams.Answer
'Activity.Finish

End If
End Sub
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
Informatix (I know, not Steve :( ), I can't figure out where I'm going wrong to try to use masked input in your BetterDialogs. Here's the code. Upon compilation, it errors. I know that I need to create a statement with an equals sign, with your Format parameter?


Sub NutritLabelWeightDialogBoxSub 'Dialog box code called from button.
Dim DialogBoxParams As BD_InputBoxParams
DialogBoxParams.Initialize
DialogBoxParams.Question = "<I> Enter food weight</I>"
DialogBoxParams.QuestionTextSize = 22
DialogBoxParams.SpaceBetween = 4dip
DialogBoxParams.InputTextSize = 24
DialogBoxParams.InputType = DialogBoxParams.INPUT_TYPE_DECIMAL_NUMBERS
DialogBoxParams.Gravity = Gravity.CENTER_VERTICAL + Gravity.CENTER_HORIZONTAL
DialogBoxParams.ValidationCallback = "NutritLabelWeightNumericValidation"
DialogBoxParams.Format("####.###")

Dim DialogButtonParameters As Int = NutritLabelWeightDialogBox.InputBox("Number input", DialogBoxParams, "OK", "Cancel", "", Null)

If DialogButtonParameters = DialogResponse.POSITIVE Then
'Log(DialogBoxParams.Answer)
'Label2.Text = DialogBoxParams.Answer
'Activity.Finish

End If
End Sub
Replace
DialogBoxParams.Format("####.###")
by
DialogBoxParams.Format = "####.###"
 
Upvote 0

bodycode

Member
Licensed User
Longtime User
Actually, I think this is a relatively simple problem if you use the IME library - you can ensure that only the numeric keyboard shows, filter the input so it only accepts numbers (including - and . and leading 0), then do what you like if it is not numeric. I took the liberty of modifying one of the B4A sample programs (rather than write a specific example) - see the NumberOnly program included here) so that one field will only accept the filtered numeric input and test to ensure that it really is numeric (and does not contain something like more than one decimal). Check the code used for the EditText3 field. Also, you can control when the keyboard opens and closes. You can also change the filter that presently is set as "0123456789.-" to "0123456789" so the - and/or decimal cannot be entered.

Hi Tom, this is Marshall, after a long time being absent here.

for some reason, TextEdit3 numeric text field is not filtering for a decimal point. Do you want me to send you a screen shot? For some reason, my phone keypad is malfunctioning on this code?

Regards,
Marshall
 
Upvote 0

bodycode

Member
Licensed User
Longtime User
Actually, I think this is a relatively simple problem if you use the IME library - you can ensure that only the numeric keyboard shows, filter the input so it only accepts numbers (including - and . and leading 0), then do what you like if it is not numeric. I took the liberty of modifying one of the B4A sample programs (rather than write a specific example) - see the NumberOnly program included here) so that one field will only accept the filtered numeric input and test to ensure that it really is numeric (and does not contain something like more than one decimal). Check the code used for the EditText3 field. Also, you can control when the keyboard opens and closes. You can also change the filter that presently is set as "0123456789.-" to "0123456789" so the - and/or decimal cannot be entered.

Fixed it. Had to do input_type_decimal_numbers. That worked.
 
Upvote 0
Top