Customdialog problem

mrossen

Active Member
Licensed User
Longtime User
Hi,

I have a customdialog with a add button.

My problem is when I press the button I would like to validate some data before leaving the dialogbox. Is this possible

Now I am reload the sub, but that reset my text fields.

Thanks

My code for now is:

B4X:
Dim dialog As CustomDialog
   Dim pnl As Panel
   Dim Subscription As String
   
   pnl.Initialize("")
   pnl.LoadLayout("inputdialog")
   
   InputDialogEditTextSubscription.InputType = InputDialogEditTextSubscription.INPUT_TYPE_PHONE

   dialog.AddView(pnl, 0dip, 0dip, 100%x, 240dip)
   dialog.Show("Tilføj profil", "Tilføj", "Annuller", "",  LoadBitmap(File.DirAssets, "ic_menu_car.png"))
   
   If dialog.Response = -1 Then
   
      If InputDialogEditTextProfileName.Text.Length > 0 AND InputDialogEditTextSubscription.Text.Length > 0 Then 
         If InputDialogButtonButtonSubscription.Checked = True Then Subscription = "True"
         If InputDialogButtonButtonNoSubscription.Checked = True Then Subscription = "False"
      
         AddProfileToSql(InputDialogEditTextProfileName.Text, Subscription, InputDialogEditTextSubscription.Text)
   
         ViewProfiles
      Else
         AddProfile
      End If
      
   End If
   
   If dialog.Response = -2 Then
   
      ViewProfiles
   
   End If

Mogens
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
It is better to use DialogResponse instead of the constants values:
B4X:
If dialog.Response = DialogResponse.Positive Then ...

You can create a loop such as:
B4X:
'create dialog here
Do While True
 dialog.Show
 If dialog.Response = DialogResponse.Positive Then 
  'Verify value.
  'If good then Exit loop (Exit)
 Else If dialog.Response = DialogResponse.Negetive Then 
  ViewProfiles
  Exit
 Else 'This is important as the dialog will be canceled if the activity is paused.
  Exit
 End If
Loop
 
Upvote 0
Top