Android Question Dialog only in one point of code.

netsistemas

Active Member
Licensed User
Longtime User
This code
B4X:
Sub btnDate_Click
    'only CANCEL needed
    Wait For (Dialog.ShowTemplate(DateTemplate, "", "", "CANCEL")) Complete (Result As Int)
    If Result = XUI.DialogResponse_Positive Then
        btnDate.xLBL.Text = DateTime.Date(DateTemplate.Date)
    End If
End Sub

with definition of vars, are necessary put in all pages?
are there any thenic for put this code on in a MODULE or class.

y try to put somethin like this:
B4X:
Sub GetFechaDialogo(Act As Activity, TextoSolicitado As String ) As ResumableSub
    Private Dialog As B4XDialog
    Private DateTemplate As B4XDateTemplate

    Dialog.Initialize ( Act)
    
    Dialog.Title = "XUI Views"
    
    DateTemplate.Initialize
    DateTemplate.MinYear = 2016
    DateTemplate.MaxYear = 2030
    
    Dim RtFecha As String= ""
    Dim td As DateDialog

    'Msgbox(td.Version,"")
    td.Year = DateTime.GetYear(DateTime.Now)
    td.Month = DateTime.GetMonth(DateTime.Now)
    td.DayOfMonth= DateTime.GetDayOfMonth(DateTime.Now)
    
    
    'only CANCEL needed
    Wait For (Dialog.ShowTemplate(DateTemplate, "", "", "CANCEL")) Complete (Result As Int)
    If Result = Xui.DialogResponse_Positive Then
        RtFecha = DateTime.Date(DateTemplate.Date)
    End If
    
    
    Return RtFecha
    
End Sub

in a mod, but show a error:
static mod, no event detect (sorry, error showme in spanish)
 

netsistemas

Active Member
Licensed User
Longtime User
Me intention is put all code in a only point, and execute a generic methog for use template.
Define only one variable for all proyect.
Something like this:
B4X:
private Sub CreateFecha

    Private DateTemplate As B4XDateTemplate
    Private Dialog As B4XDialog
    Private XUI As XUI

    DateTime.DateFormat="dd-MM-yyyy"
    Private Base As B4XView
    'Base = B4XPages.GetNativeParent(Me)   'error in b4x for b4j
base = root 'for b4x    
    Dialog.Initialize(Base)
    Dialog.Title = "Date Selector"
   

    DateTemplate.Initialize
    DateTemplate.MinYear = 2016
    DateTemplate.MaxYear = 2030
End Sub

and this other code too:
B4X:
Sub PUBLICPROCESSFORALLPROYECT AS STRING
    'only CANCEL needed
    Wait For (Dialog.ShowTemplate(DateTemplate, "Aceptar", "", "CANCEL")) Complete (Result As Int)
    If Result = XUI.DialogResponse_Positive Then
        return = DateTime.Date(DateTemplate.Date)

    End If
 
Last edited:
Upvote 0

netsistemas

Active Member
Licensed User
Longtime User
Perfect, this is what a need.
Only a simple adicional questión:
Are any problem in do INITIALIZE in the same site that do the wait?
that is:

B4X:
Sub cmdFecha_Click
'    GetFecha(Sender)
    SelectFecha(Sender)
End Sub

Sub SelectFecha(Control As B4XView)
    B4XPages.MainPage.MyDateDialog.Initialize(Root)
'    B4XPages.MainPage.MyDateDialog.Parent = Root
    Wait For (B4XPages.MainPage.MyDateDialog.Show) Complete(Result As String)
    If Result <> "" Then
        Control.Text = Result
        Control.Tag = Result
    End If
End Sub


Adicional, i change the code to use a button for TODAY (HOY)
B4X:
Public Sub Show As ResumableSub
    Dim strResult As String = ""
    'only CANCEL needed
    Dim Salir As Boolean
    Salir = False
    Do While Salir = False
        Wait For (Dialog.ShowTemplate(DateTemplate, "Aceptar",   "HOY", "CANCEL")) Complete (Result As Int)
        If Result = xui.DialogResponse_Positive Then
            strResult = DateTime.Date(DateTemplate.Date)
            Salir = True
        ELSE IF Result = xui.DialogResponse_Negative  Then
            DateTemplate.Date = DateTime.Now

            'strResult = DateTime.Date(DateTemplate.Date)
        Else
            Salir = True
        End If
    Loop
    Return strResult
End Sub

thank you.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
The attached project can be an example
I have redone your example without creating a new Date Dialog class module. I get everything you get with your example. I do not think it is any better or superior, but has a little less code. But, I would like you to check it out to see if you find any flaws or sink holes. If you make any improvements, please share.
 

Attachments

  • B4XPagesSelectingDatesFromMutliplePages.zip
    12 KB · Views: 143
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
That's fine, well done.

You can delete the initialization in B4XPage_Created of clsPageOne, since you reinitialize in B4XPage_Appear.



[You don't need to declare a view/b4xview if you will use only its events. Private btnDate As Button is not needed]
 
Last edited:
Upvote 0
Top