Android Question Anotherdatepicker showtemplate(datetemplate)

Colin Evans

Active Member
Licensed User
Longtime User
Hi, I'm keen to use the new anotherdatepicker.b4xlib but I'm at a loss to how to use it, the examples look very good but they seem to rely on a DateTemplate, and apparently there's loads of templates, unfortunately I can't seem to find them or get the new anotherdatepicker to work, I've looked at the example Xui Views Example but can't figure out How I would transfer the way the btnDate would transfer into my app, I've tried and I thought I had added the required libraries etc but I get unknown member showtemplate and I've no idea where to find the DateTemplate
 

Mahares

Expert
Licensed User
Longtime User
get unknown member showtemplate and I've no idea where to find the DateTemplate
You need B4XDialog , B4XDateTemplate. (both in XUI Views Lib).Here is a complete project that displays the date dialog and let you select a date and automatically paste it to a label. Make sure you check XUI Views library.
B4X:
Sub Globals
    Private Dialog As B4XDialog   'need XUI Views 2.30 checked (internal lib)
    Private DateTemplate As B4XDateTemplate
    Private XUI As XUI  'you declare this if you use the XUI colors
    Private lbl As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
    lbl.Initialize("lbl")
    Activity.AddView(lbl,300dip,0,150dip,75dip)  'via code, but you can do it via designer
    lbl.Color=XUI.Color_Blue
    Dialog.Initialize (Activity)
    Dialog.Title = "Select a date"
    DateTemplate.Initialize
    DateTemplate.MinYear = 2016
    DateTemplate.MaxYear = 2030
    Wait For (Dialog.ShowTemplate(DateTemplate, "", "", "CANCEL")) Complete (Result As Int)
    If Result = XUI.DialogResponse_Positive Then
        Log($"Selected Date is: ${DateTime.Date(DateTemplate.Date}"$ ))
        lbl.Text=DateTime.Date(DateTemplate.Date)
        lbl.TextColor =XUI.Color_Yellow
    End If   
End Sub
 
Upvote 0

mangojack

Well-Known Member
Licensed User
Longtime User
Just to add ... That AnotherDatePicker.b4xlib was created as an example only to demonstrate the new .b4xlib's.
 
Upvote 0

Colin Evans

Active Member
Licensed User
Longtime User
Hi, I know I am basic and learning very slowly but I can't get the logic to work in my existing program my version of XUI Views is showing 2.24 and I can't find the version you mention 2.30

I've tried ding via a designer form, but can't get it to work, all I want is basically the Activity_create to get todays date in YYYY-MM-DD format, assign it to a text field and then have a button which launches the DateTemplate (anotherDatePicker) where the user can select a date, updating the text field,

It can't be that hard but understanding the code is proving to be too difficult as I seem to be going round and round creating different errors,

Sorry to be so dumb
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I've tried ding via a designer form, but can't get it to work, all I want is basically the Activity_create to get todays date
The latest version of B4X Views lib (internal library) is at the end of post 1 in this link:
But you are probably ok with the version you have.
Here is a complete project attached you can unzip and run and will do what you asked for:
B4X:
Sub Globals
    Private Dialog As B4XDialog   'need XUI Views 2.30 checked (internal lib)
    Private DateTemplate As B4XDateTemplate
    Private XUI As XUI  'you declare this if you use the XUI colors
    Private edt As EditText
    Private btn As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)  
    Activity.LoadLayout("main")   'has a button and an edittext
    Dialog.Initialize (Activity)
    Dialog.Title = "Select a date"
    DateTemplate.Initialize
    DateTemplate.MinYear = 2016
    DateTemplate.MaxYear = 2030
    DateTime.DateFormat= "yyyy-MM-dd"
    edt.Text=DateTime.Date(DateTime.Now)
    edt.Color=XUI.Color_Red
End Sub

Sub btn_Click
    Wait For (Dialog.ShowTemplate(DateTemplate, "", "", "CANCEL")) Complete (Result As Int)
    If Result = XUI.DialogResponse_Positive Then
        Log($"Selected Date is: ${DateTime.Date(DateTemplate.Date}"$ ))
        edt.Text=DateTime.Date(DateTemplate.Date)
        edt.TextColor =XUI.Color_Yellow
    End If   
End Sub
 

Attachments

  • B4XDateTemplate050920.zip
    9.4 KB · Views: 238
Upvote 0

Colin Evans

Active Member
Licensed User
Longtime User
Very good, easy to understand, thanks a lot
But when I copy your example into my form when I click the 'btn' (btn_click) I get the following error
B4X:
b4xdialog$ResumableSub_ShowTemplateresume (java line: 1150)
Any idea's
 
Last edited:
Upvote 0

Mahares

Expert
Licensed User
Longtime User
But when I copy your example into my form when I click the 'btn' (btn_click) I get the following error
Your best bet is to export your project as zip to the forum. Someone will probably figure it out for you, if I do not get to it or unable to.
You may try to make sure you have the latest XUI Views lib, just in case.
 
Upvote 0

Colin Evans

Active Member
Licensed User
Longtime User
I've added another activity page to the project and copied your code into that page and it works as it should so there's obviously a conflict somewhere in my code, I'll have a good look and get back to you, thanks
 
Upvote 0

Colin Evans

Active Member
Licensed User
Longtime User
Hi, I've put part of my program as a separate app to try and identify via I can't access the DatePicker as shown in the example so generously supplied by Mahares, I have tried many ways to get round it but can't find where i am going wrong. Please excuse the basic coding, any suggestions gratefully received, many thanks Colin
 

Attachments

  • electric test.zip
    12.5 KB · Views: 200
Upvote 0

Mahares

Expert
Licensed User
Longtime User
any suggestions gratefully received
You forgot to add these 2 lines: below this line: SetHeader(Array As String("Date","From","To","Consumption"))
B4X:
 Dialog.Initialize (Activity)   'this one
    Dialog.Title = "Select a date"   'also this one.
I took a very quick look at the project. Once you add the 2 lines, it will show you the date template. After that, I do not know what you do with the date. But at least you can select your date and it shows you the date selected in the logs..
 
Upvote 0

Colin Evans

Active Member
Licensed User
Longtime User
Thank you very much, works, god it's frustrating when you don't know what you're doing, this forum as to be the best for experts and learners alike, thanks again
 
Upvote 0
Top