Android Question Using AnotherDatePicker in Dialog2 [SOLVED]

ThePuiu

Active Member
Licensed User
Longtime User
Is it possible to use another DatePicker control in a Dialog2 dialog?
I created a layout on which I added anotherDatePicker control. When the dialog is displayed, I receive the following message:

B4X:
Error occurred on line: 156 (AnotherDatePicker)
java.lang.RuntimeException: Object should first be initialized (B4XView).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:67)
    at anywheresoftware.b4a.objects.B4XViewWrapper.getViewObject(B4XViewWrapper.java:101)
    at anywheresoftware.b4a.objects.B4XViewWrapper.getColor(B4XViewWrapper.java:399)
    at isorihner.softxxi.anotherdatepicker._datefield_textchanged(anotherdatepicker.java:621)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.objects.EditTextWrapper$1.afterTextChanged(EditTextWrapper.java:83)
    at android.widget.TextView.sendAfterTextChanged(TextView.java:10991)
    at android.widget.TextView.setText(TextView.java:6431)
    at android.widget.TextView.setText(TextView.java:6231)
    at android.widget.EditText.setText(EditText.java:146)
    at android.widget.TextView.setText(TextView.java:6188)
    at android.widget.TextView.setTransformationMethod(TextView.java:2814)
    at android.widget.TextView.applySingleLine(TextView.java:10651)
    at android.widget.TextView.setSingleLine(TextView.java:10625)
    at anywheresoftware.b4a.objects.EditTextWrapper.setSingleLine(EditTextWrapper.java:140)
    at isorihner.softxxi.anotherdatepicker$ResumableSub_DesignerCreateView.resume(anotherdatepicker.java:802)
    at isorihner.softxxi.anotherdatepicker._designercreateview(anotherdatepicker.java:744)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:197)
    at anywheresoftware.b4a.objects.CustomViewWrapper.AfterDesignerScript(CustomViewWrapper.java:61)
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:162)
    at anywheresoftware.b4a.objects.PanelWrapper.LoadLayout(PanelWrapper.java:134)
    at isorihner.softxxi.arhivaoferte$ResumableSub_Amanare_Click.resume(arhivaoferte.java:915)
    at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:48)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
    at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:43)
    at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:267)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:137)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:197)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
    at anywheresoftware.b4a.agraham.dialogs2.InputDialog$ExtendedBALayout$1.run(InputDialog.java:2536)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:216)
    at android.app.ActivityThread.main(ActivityThread.java:7266)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:975)


To open the dialog I use the following code:
B4X:
Dim sf As Object = DialogAmanareStergere.ShowAsync("Amanare / refuzare oferta", "Ok", "Cancel", "", Null, True)
    Dim w As Int = 100%x
    Log(100%x & " Wide, " & 100%y & "High")
    If 100%Y < 100%x Then w = 100%y
    DialogAmanareStergere.SetSize(w, 350dip)
    Wait For (sf) Dialog_Ready(pnl As Panel)
    pnl.LoadLayout("DialogAmanareStergereLayout")
    
    Dim first As Long = DateUtils.SetDate(DateTime.GetYear(DateTime.Now), DateTime.GetMonth(DateTime.Now),1)
    DataAmanare.Date = first
 

ThePuiu

Active Member
Licensed User
Longtime User
I tried to use B4XDateTemplate but the opening of the date selection dialog is done under the dialog in which I have control ... How can I avoid this?
B4X:
Sub Amanare_Click
    Dim sf As Object = DialogAmanareStergere.ShowAsync("Amanare / refuzare oferta", "Ok", "Cancel", "", Null, True)
    Dim w As Int = 100%x
    Log(100%x & " Wide, " & 100%y & "High")
    If 100%Y < 100%x Then w = 100%y
    DialogAmanareStergere.SetSize(w, 550dip)
    Wait For (sf) Dialog_Ready(pnl As Panel)
    pnl.LoadLayout("DialogAmanareStergereLayout")
    
    DateAmanare.Initialize
    DateAmanare.Date = DateTime.Now
    lDateAmanare.Text = $"Selected Date: $Date{DateAmanare.Date}"$
    
    Dialog.Initialize(Activity)
    Dim cs As CSBuilder
    Dialog.Title = cs.Initialize.Size(24).Append("Select Date").PopAll
End Sub

Sub lDateAmanare_Click
    Wait For (Dialog.ShowTemplate(DateAmanare, "", "", "CANCEL")) Complete (Result As Int)
    lDateAmanare.Text = $"Selected Date: $Date{DateAmanare.Date}"$
End Sub
 
Upvote 0

ThePuiu

Active Member
Licensed User
Longtime User
I changed the code. Now when you click on the lDataAmanare label, the B4XDateTemplate control opens (DialogData), but the parent dialog (MainDialog ) disappears...

B4X:
Sub Globals
    Private MainDialog As B4XDialog
    Private DialogData As B4XDialog
    Private lDataAmanare As B4XView
    Private DateAmanare As B4XDateTemplate
End Sub

Sub Activity_Create(FirstTime As Boolean)
    MainDialog.Initialize(Activity)
    DialogData.Initialize(Activity)   
End Sub

Sub Amanare_Click
    Dim w As Int = 100%x
    If 100%Y < 100%x Then w = 100%y

    Dim xui As XUI
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, (100%y - 500dip) / 2, w, 500dip)
    p.LoadLayout("DialogAmanareStergereLayout")
    
    DateAmanare.Initialize
    DateAmanare.Date = DateTime.Now
    lDataAmanare.Text = $"Data amanare: $Date{DateAmanare.Date}"$

    MainDialog.PutAtTop = True
    Dim rs As ResumableSub =  MainDialog.ShowCustom(p, "OK", "", "CANCEL")
    Wait For (rs) Complete (Result As Int)
    If Result = xui.DialogResponse_Positive Then
        
    End If
End Sub

Sub lDataAmanare_Click
    Wait For (DialogData.ShowTemplate(DateAmanare, "", "", "CANCEL")) Complete (Result As Int)
    DataAmanare.Text = $"Data amanare: $Date{DateAmanare.Date}"$
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…