Android Question Dialogs library - Prevent Dialog Closing

Sgdva

Member
Licensed User
Background:
I need to check for the input that the users feed the library dialog with; if it does not meet the criteria, the dialog should not close until it does or the user cancels.
Basically, an EditText should not be empty (that is built into the library dialog).
Problem:
I have not found a way on how to prevent that the DialogPanel closes after the user hits "Yes".
The diagram flow will be: I need to let the user click "Yes", check if the criteria is met, and if it is not, the dialog should stay with the data that has been filled already.

B4X:
Sub btnEnterDetails_Click
   Dim dialog As CustomLayoutDialog
   Dim sf As Object = dialog.ShowAsync("", "Yes", "Cancel", "No", Null, False)
   Wait For (sf) Dialog_Ready (DialogPanel As Panel)
 
   DialogPanel.LoadLayout("DetailsDialog")
   Dim disable() As Boolean = Array As Boolean(False)
   AutoClose(dialog, lblSeconds, disable)
   Wait For (sf) Dialog_Result (Result As Int)
   disable(0) = True 'disable the AutoClose timer
   sf.Preserve 'Something like this to prevent closing while evaluating criteria
   If Result = DialogResponse.POSITIVE Then
   If EditText.Text = "" then
   ToastMessageShow("Write something!", False)
   else
   sf.close 'Something like this to prevent closing while evaluating criteria
   end if
   End If
End Sub

Sub AutoClose (TimedDialog As CustomLayoutDialog, UpdateLabel As Label, Disable() As Boolean)
   UpdateLabel.Text = 9 '9 seconds
   Do While UpdateLabel.Text > 0
     Sleep(1000)
     'the timer was disabled
     If Disable(0) = True Then Return
     UpdateLabel.Text = NumberFormat(UpdateLabel.Text - 1, 0, 0)
   Loop
   TimedDialog.CloseDialog(DialogResponse.CANCEL)
End Sub
I am using Erel Example in his second post. As in example, if do you want to do something you should fill it up with an Edit Text that I set there below it; I would like to send a toast message "no action input!" but leave the Dialog open so they can still work on it.

Further thoughts
I know that if I use 'If Result = DialogResponse.POSITIVE And EditText.Text = "" then'
and then handle by that logic, however, I am going to work with multiple criteria later on and I would like to know how to prevent the Dialog close to handle any future scenario that might come along
 
Last edited:

Sgdva

Member
Licensed User
It is difficult to read your post. Please use regular font.

You can hide the OK button and add your own button instead. This will allow you to do whatever you like (show a message or close the dialog if the input is valid).
That is kind of my "work around" at the moment, however, I would like to know if there is anything native within this library to avoid that and use the proper command to do so.
PS: I am sorry on the font, it has been updated
 
Upvote 0
Top