Android Question input dialog - not closing

cirollo

Active Member
Licensed User
Longtime User
HI!

I've an input dialog, I would like that is not closed if I'm in a specific situation, this is my code:

B4X:
Sub LstDisegni_ItemClick (Position As Int, Value As Object)
   Dim numriga As Int
   Dim rigaord As String
   Dim bmp As Bitmap
   Dim Dettaglio As InputDialog
   Dettaglio.InputType = Dettaglio.INPUT_TYPE_NUMBERS
   Dim ret As Int
   bmp.Initialize(File.DirAssets, "warning_gemitex.png")
 
   'verichiamo se questo articolo è già presente e, in tal caso, inizializziamo la quantità
   Dim esiste_art_dis As String
   esiste_art_dis="N"
   stringa_SQL = "select Quantita from Ordini where IdOrdine='"&Ordine.IdOrdine&"' and CodiceArticolo='"&Ordine.Codart&"' and CodiceDisegno='"&Value&"'"
   Dim cur As Cursor
   cur = SQL1.ExecQuery(stringa_SQL)
   For i = 0 To cur.RowCount-1
       cur.Position = i
       esiste_art_dis = cur.GetString("Quantita")
   Next
   If esiste_art_dis="N" Then
       Dettaglio.Input = ""
       ret = Dettaglio.Show("Qtà in Pezzi ("&LblImbArt.Text.Trim.SubString(4)&")", "Inserimento in Ordine", "Conferma", "", "Annulla", bmp)
   Else
       Dettaglio.Input = esiste_art_dis
       ret = Dettaglio.Show("Qtà in Pezzi ("&LblImbArt.Text.Trim.SubString(4)&")", "Inserimento in Ordine", "Conferma", "Annulla", "Elimina Articolo", bmp)
   End If
 
   If ret = -1 Then
       Dim qtaimballo As Double
       stringa_SQL="SELECT QtaImballo FROM Articoli where CodiceArticolo='"&Ordine.Codart&"'"
       Dim cur As Cursor
       cur = SQL1.ExecQuery(stringa_SQL)
       For i = 0 To cur.RowCount-1
           cur.Position = i
           qtaimballo = cur.GetString("QtaImballo")
       Next
       If qtaimballo = 0 Then
           qtaimballo = 1
       End If
 
       If Dettaglio.Input.Trim = "" Or Dettaglio.Input.trim <= 0 Or (Dettaglio.Input.Trim Mod qtaimballo) <> 0 Then
           Msgbox2("Attenzione, Verificare Quantità!",Main.nomeprog,"","Ok","",LoadBitmap (File.DirAssets, "warning_gemitex.png"))

IN THIS CASE I WANT TO RETURN TO THE INPUT DIALOG, AVOIDING IT TO CLOSE!


       Else
......



how can I do this?

regards,
 

RB Smissaert

Well-Known Member
Licensed User
Longtime User
HI!

I've an input dialog, I would like that is not closed if I'm in a specific situation, this is my code:

B4X:
Sub LstDisegni_ItemClick (Position As Int, Value As Object)
   Dim numriga As Int
   Dim rigaord As String
   Dim bmp As Bitmap
   Dim Dettaglio As InputDialog
   Dettaglio.InputType = Dettaglio.INPUT_TYPE_NUMBERS
   Dim ret As Int
   bmp.Initialize(File.DirAssets, "warning_gemitex.png")
 
   'verichiamo se questo articolo è già presente e, in tal caso, inizializziamo la quantità
   Dim esiste_art_dis As String
   esiste_art_dis="N"
   stringa_SQL = "select Quantita from Ordini where IdOrdine='"&Ordine.IdOrdine&"' and CodiceArticolo='"&Ordine.Codart&"' and CodiceDisegno='"&Value&"'"
   Dim cur As Cursor
   cur = SQL1.ExecQuery(stringa_SQL)
   For i = 0 To cur.RowCount-1
       cur.Position = i
       esiste_art_dis = cur.GetString("Quantita")
   Next
   If esiste_art_dis="N" Then
       Dettaglio.Input = ""
       ret = Dettaglio.Show("Qtà in Pezzi ("&LblImbArt.Text.Trim.SubString(4)&")", "Inserimento in Ordine", "Conferma", "", "Annulla", bmp)
   Else
       Dettaglio.Input = esiste_art_dis
       ret = Dettaglio.Show("Qtà in Pezzi ("&LblImbArt.Text.Trim.SubString(4)&")", "Inserimento in Ordine", "Conferma", "Annulla", "Elimina Articolo", bmp)
   End If
 
   If ret = -1 Then
       Dim qtaimballo As Double
       stringa_SQL="SELECT QtaImballo FROM Articoli where CodiceArticolo='"&Ordine.Codart&"'"
       Dim cur As Cursor
       cur = SQL1.ExecQuery(stringa_SQL)
       For i = 0 To cur.RowCount-1
           cur.Position = i
           qtaimballo = cur.GetString("QtaImballo")
       Next
       If qtaimballo = 0 Then
           qtaimballo = 1
       End If
 
       If Dettaglio.Input.Trim = "" Or Dettaglio.Input.trim <= 0 Or (Dettaglio.Input.Trim Mod qtaimballo) <> 0 Then
           Msgbox2("Attenzione, Verificare Quantità!",Main.nomeprog,"","Ok","",LoadBitmap (File.DirAssets, "warning_gemitex.png"))

IN THIS CASE I WANT TO RETURN TO THE INPUT DIALOG, AVOIDING IT TO CLOSE!


       Else
......



how can I do this?

regards,

Shouldn't your If block be within the loop?

RBS
 
Upvote 0

cirollo

Active Member
Licensed User
Longtime User
sorry, I don't understand....

I've to check the value of the input field (a number in this case) when the user clicks on the "OK" button.
The OK returns me -1, this means (I suppose) the dialog must close.

I need to avoid this in case the number entered on the dialog doesn't match certain rules.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Don't use modal dialogs at all. Only use the async calls.

Example:
B4X:
Sub Test
   Do While True
       Dim id As InputDialog
       Dim sf As Object = id.ShowAsync("", "Enter your name", "Ok", "", "", Null, False)
       Wait For (sf) Dialog_Result(Result As Int)
       If id.Input.Length > 5 Then
           Exit
       Else
           ToastMessageShow("Name too short", True)
       End If
   Loop
   Activity.Title = id.Input
End Sub
 
Upvote 0
Top