Dialogs return immediate result lol?

Penko

Active Member
Licensed User
Longtime User
Hello guys!

It has been driving me nuts since last night. I am testing on two devices:
HTC Desire Android 2.2
Next7 Tablet Android 4.0

Here is the Dialogs code:

B4X:
Sub updateQuantity(theProduct As tProduct)

   zCommon.LogT("requestQuantity() theProduct = " & theProduct , "")

Dim quantityDialog2 As InputDialog
quantityDialog2.InputType = quantityDialog2.INPUT_TYPE_PHONE
quantityDialog2.Hint = "How much?"

If(theProduct.Field1<> 0) Then
   quantityDialog2.Input = theProduct.Field5
End If

quantityDialog2.Show("The quantity for this product (e.g 1 item)", _
"Enter Quantity", "Save", "Cancel", "", Null)

Msgbox(quantityDialog2.Response, "") ' this is triggered together with the dialog popup. Instead of waiting to click "OK/Cancel", etc..., the result is ready immediately.

Dim quantity As Double

Try
   quantity = quantityDialog2.Input
Catch
   quantity = 0
End Try

'Dim quantity As Double : quantity = 5 ' if I comment out the dialogs and use constant value, my logic below works. With a dialog, it is never executed.

If(quantity <> 0) Then

   theProduct.Initialize(theRecipeProduct.Field1, _
   theProduct.Field2, _
   theProduct.Field3, _
   theProduct.Field4, _
   quantity, _
   theProduct.Field6)
   
   sqlProducts.LinkIt(theProduct)

   painter("RELOAD")

Else

   zCommon.showError("You have to specify not-null quantity!", _
   "Error")

End If

The problem is that on my tablet(Android 4.0), the dialog returns the value immediately. If it matters, the returned value is -3. So, I call .Show() but get the result together with that. The result is that the user can't type anything immediately and when they do it, the Sub has probably already returned and nothing happens. Once again, I get the messagebox "You have to specify non-null quantity" immediately, together with the Dialog showing...!?

On the HTC Desire, this works perfectly. It waits for the user to choose quantity and when they click "OK", it is then that the rest of the logic is executed.

I definitely classify it as a bug. However, is there anything that I am missing to workaround it?
 
Last edited:

Roger Garstang

Well-Known Member
Licensed User
Longtime User
Works fine on my devices too. Could it be something to do with INPUT_TYPE_PHONE? Perhaps that device handles that keyboard in a special way or has it disabled? Try just setting it to INPUT_TYPE_NUMBERS or INPUT_TYPE_TEXT and see if it does the same thing. -3 is also what response returns when Back is pressed (DialogResponse.CANCEL).
 
Last edited:
Upvote 0

Penko

Active Member
Licensed User
Longtime User
It hasn't to do with the KEYBOARD type. I tested with all your suggestions + the rest of them, nothing changed.

The problem is with InputDialog. I am actively using DateDialog and it works perfectly.

It is just that the result is returned immediately. I think it is the moment when the keyboard starts appearing. Pretty strange!

Even if it is a specific problem of my device, I can't rely on this for production.

P.S Did you test on Android 4.0 or other version?

P.S2 - I made a small project and as in most cases of mine, it works like a charm! It means this library conflicts with something else I am using in my big project. But anyway, can more people test this out to verify it's working not forgetting to mention the version they are testing on?
 

Attachments

  • dialogsPenko.zip
    5.8 KB · Views: 245
Last edited:
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
It works as expected. I've seen in the dialogsExample, coding as:
B4X:
Dim ret As Int 
ret=DialogResponse.CANCEL 
ret=quantityDialog2.Show("The quantity for this product (e.g 1 item)", _
"Enter Quantity", "Save", "Cancel", "", Null)
I am curious why this 'ret' variable is predefined with 'cancel', but probably there is a reason for this. Perhaps you could give it a try.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I tested the project you posted on a 7 inch tablet made in China with OS 4.03. It worked with no problems. The only thing I noticed is when you enter a value and press 'Cancel' it still says 'Success. So i added a couple of lines for that. Not a big deal. Here is the full sub updateQuantity()
B4X:
Sub updateQuantity()

   Dim quantityDialog2 As InputDialog
   quantityDialog2.InputType = quantityDialog2.INPUT_TYPE_PHONE
   quantityDialog2.Hint = "How much?"
   
   Dim ret As Int
   ret=quantityDialog2.Show("The quantity for this product (e.g 1 item)", _
   "Enter Quantity", "Save", "Cancel", "", Null)

   If ret=DialogResponse.POSITIVE Then  'Added by Mahares 8/8/12
         Dim quantity As Double
         Try
             quantity = quantityDialog2.Input
         Catch
             quantity = 0
         End Try
         If(quantity <> 0) Then
            Msgbox("The user entered a quantity of " & quantity, "Success")
         Else
            Msgbox("You have to specify not-null quantity!", _
             "Error")
         End If
   Else   
      Msgbox("You cancelled the input","")  'Added by Mahares 8/8/12
   End If

End Sub
 
Upvote 0

Penko

Active Member
Licensed User
Longtime User
Guys you are just pretty fast and have gone too far away while I was sleeping and couldn't reply. I will reply in sequence:

General - you've missed the part where I say that this small project works on MY tablet too. It is the second time something doesn't work for me and when I isolate it in a small project, it works perfectly. That's why I said it maybe conflicts with something else inside my big project.

Last night, I was further shocked when I found an activity of mine which has a similar quantity dialog working. So, the summary is, on two activities, these dialogs fail, on a third one it works. Now I have to compare the use of objects on these activities and catch the problem.

@mc73, the ret variable in this cases gets the value from the show(). As in my case the .show() returns immediately, it is probably the same. I will of course give it a try.

@Mahares, thank you for the time spent on correcting my code. However, it was for demonstration purposes only around the dialog .show(). I check the response in my real code. But thanks again! Edit: I tested your code and it shows the message "You cancelled the input..." immediately. The problem persists with this activity.

@marget, I am using B4A 2.02.

Now that I found an Activity where a similar code works, I will try to catch the guilty object/feature causing this.


Update: I did a serious amount of investigation and concluded the following:
- if I call the Sub from a button - e.g btnCancel_Click(because this is currently free of code), it works and the modal behaves properly.
- if I go to my selectorActivity(where I select the product), use CallSubDelayed2 to return to the previous one, it DOESN'T work.

So, I suppose it has to do with how CallSubDelayed works. I am not much aware but it isn't normal using the same function for these two cases to produce different behavior.

Once more, if I stay on my first window and attach the function to a button, it works perfectly.

If you check the project, I have tried to reproduce the CallSubDelayed the way I am using it in my big project but unfortunately, it works perfectly in the small project and doesn't show this problem.

I believe this is where my research ends. I will be working on other parts of the application and if I don't end up with something in my head, I'll just go for another solution refraining from the use of modal dialogs.
 
Last edited:
Upvote 0
Top