Android Question DatePicker passing parameters

Colin Evans

Active Member
Licensed User
Longtime User
Hi (Erel)

I have been working with the demo regarding the datepicker which works brilliantly in the example given, however I wish to expand on the program to have various screens available for my application, so I thought I'd use the Two Activites Layout example as the base of the program, which I believe is the right way forward, as you can see from the example attached its nearly there but I can't figure out why the 'AnotherDatePicker' doesn't kick off the relevant part of the code to search the excel spreadsheet to match the dates

At present only the LockTimes is where I'm working but I just can't get my head round what i need to do to get the information from the spreadsheet, sorry If I'm not that clear, hope you can help point me in the right direction

Many thanks
 

Colin Evans

Active Member
Licensed User
Longtime User
Whats the best to upload, the zip file is bigger than 512kb and if i split it the upload only allows the .zip file to upload not the .z01 .z02 files, I have renamed the .z0 files but it will obviously cause you additional work having to rename and then unzip, sorry but hope you can help

The following files attached

locktimes.zip
locktimes1.zip rename to locktimes.z01
locktimes2.zip rename to locktimes.z02
locktimes3.zip rename to locktimes.z03
 
Upvote 0

Colin Evans

Active Member
Licensed User
Longtime User
Tried again, I've also tried to incorporate the GPS (next element) but having problems with this also, as I explained I'm not that good at programming, I keep trying and with help I usually get there so appreciate any help you can offer many thanks.

I was using the standard Winrar to zip up everything so thats why the files were so big, sorry
 

Attachments

  • LockTimes.zip
    256.1 KB · Views: 149
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

Colin Evans

Active Member
Licensed User
Longtime User
Followed the example and made the changes but I now get the following error(s)
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (page1) Create, isFirst = true **
Class not found: b4a.example.anotherdatepicker, trying: ditl.lock.times.anotherdatepicker
Error occurred on line: 197 (AnotherDatePicker)
java.lang.RuntimeException: Class instance was not initialized (anotherdatepicker)
at anywheresoftware.b4a.debug.Debug.shouldDelegate(Debug.java:249)
at ditl.lock.times.anotherdatepicker._show(anotherdatepicker.java:756)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:702)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:336)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:246)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at ditl.lock.times.page1.afterFirstLayout(page1.java:102)
at ditl.lock.times.page1.access$000(page1.java:17)
at ditl.lock.times.page1$WaitForLayout.run(page1.java:80)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
** Activity (page1) Resume **

Line 197 being the first line in this Sub

Public Sub Show
If waitForAddToActivity Then
'not ready yey
CallSubDelayed(Me, "show")
Return
End If
holder.SetVisibleAnimated(500, True)
DrawDays
End Sub
 
Upvote 0

Colin Evans

Active Member
Licensed User
Longtime User
I got rid of the

AnotherDatePicker1.Show
which caused the above error

The program now allows me to select a date but doesn't return me into the

Sub AnotherDatePicker1_Closed (Cancelled As Boolean, Date As Long)

as it does in the original example, so it never gets to read the excel spreadsheet as it was before

ANy idea's

Sub AnotherDatePicker1_Closed (Cancelled As Boolean, Date As Long)
If Not(Cancelled) Then
DateTime.DateFormat = "dd/MM/yyyy"
DateTime.TimeFormat = "hh:mm a"
Dim year As Int = DateTime.GetYear(Date) 'ignore
Dim month As Int = DateTime.GetMonth(Date) 'ignore
Dim day As Int = DateTime.GetDayOfMonth(Date) 'ignore
Log($"Selected date: $Date{Date}"$)
End If

Dim workbook1 As ReadableWorkbook
Dim timesSheet As ReadableSheet
workbook1.Initialize(File.DirAssets, "locktimes.xls")
timesSheet = workbook1.GetSheet(0)
DateTime.DateFormat = "dd/MM/yyyy"
DateTime.TimeFormat = "hh:mm a"
Day1.Text = "Data Not Found"
lock1.Text = ""
highwater1.Text = ""
height1.Text = ""
lastlock1.Text = ""
lockclose1.Text = ""
lock2.Text = ""
highwater2.Text = ""
height2.Text = ""
lastlock2.Text = ""
lockclose2.Text = ""


DateTime.DateFormat = "dd/mm/yyyy"

If timesSheet.RowsCount > 0 Then
For row = 0 To timesSheet.RowsCount -1
Log($"Checking row: ${row}"$)
If timesSheet.GetCellValue(0, row) = DateTime.Date(Date) Then
'day 1st Lock HW Height Last Lock Lock Close
Day1.Text = timesSheet.GetCellValue(1, row)
lock1.Text = timesSheet.GetCellValue(2, row)
highwater1.Text = timesSheet.GetCellValue(3, row)
height1.Text = timesSheet.GetCellValue(4, row)
lastlock1.Text = timesSheet.GetCellValue(5, row)
lockclose1.Text = timesSheet.GetCellValue(6, row)
lock2.Text = timesSheet.GetCellValue(8, row)
highwater2.Text = timesSheet.GetCellValue(9, row)
height2.Text = timesSheet.GetCellValue(10, row)
lastlock2.Text = timesSheet.GetCellValue(11, row)
lockclose2.Text = timesSheet.GetCellValue(12, row)
End If
Next
End If

End Sub

p.s.

The AnotherDatePicker module is a direct copy of the one from the example don't know if this would cause any problem
 
Last edited:
Upvote 0

Colin Evans

Active Member
Licensed User
Longtime User
I am at a loss when Ouse the original anotherdatepicker and choose a date it returns me into the correct Sub AnotherDatePicker1_Closed but doesn't in mine
 
Upvote 0

Colin Evans

Active Member
Licensed User
Longtime User
I have tried it with the datedialog and can get it to work using that but obviously its not as nice an interface as you have to press additional buttons to get the selected date, don't suppose there's anyway to automate the click on a date selected rather than having to select continue

B4X:
Sub btnDate_Click
    Dim Dd As DateDialog
    'Dd.ShowCalendar = False
    Dd.Year = DateTime.GetYear(DateTime.Now)
    Dd.Month = DateTime.GetMonth(DateTime.Now)   
    Dd.DayOfMonth = DateTime.GetDayOfMonth(DateTime.Now)
    ret = Dd.Show("Set the required date", "DITL Date Dialog", "Continue", "Cancel", "", Bmp)
    Dim datestr As String
    Dim monthstr As String
    Dim daystr As String
    monthstr = Dd.Month
    daystr = Dd.DayOfMonth
        If monthstr.Length < 2 Then monthstr = "0" & monthstr
        If daystr.Length < 2 Then daystr = "0" & daystr
        'datestr = daystr & "/" & monthstr & "/" & year
    lblDate.Text = daystr & "/" & monthstr & "/" & Dd.Year
    '
    Dim workbook1 As ReadableWorkbook
    Dim timesSheet As ReadableSheet
    workbook1.Initialize(File.DirAssets, "locktimes.xls")
    timesSheet = workbook1.GetSheet(0)
    DateTime.DateFormat = "dd/MM/yyyy"
    DateTime.TimeFormat = "hh:mm a"
    Day1.Text = "Data Not Found"
    lock1.Text = ""
    highwater1.Text = ""
    height1.Text = ""
    lastlock1.Text = ""
    lockclose1.Text = ""
    lock2.Text = ""
    highwater2.Text = ""
    height2.Text = ""
    lastlock2.Text = ""
    lockclose2.Text = ""   
    If timesSheet.RowsCount > 0 Then
        For row = 0 To timesSheet.RowsCount -1
            Log($"Checking row: ${row}"$)
            If timesSheet.GetCellValue(0, row) = lblDate.Text Then
                'day    1st Lock    HW    Height    Last Lock    Lock Close
                Day1.Text = timesSheet.GetCellValue(1, row)
                lock1.Text = timesSheet.GetCellValue(2, row)
                highwater1.Text = timesSheet.GetCellValue(3, row)
                height1.Text = timesSheet.GetCellValue(4, row)
                lastlock1.Text = timesSheet.GetCellValue(5, row)
                lockclose1.Text = timesSheet.GetCellValue(6, row)
                lock2.Text = timesSheet.GetCellValue(8, row)
                highwater2.Text = timesSheet.GetCellValue(9, row)
                height2.Text = timesSheet.GetCellValue(10, row)
                lastlock2.Text = timesSheet.GetCellValue(11, row)
                lockclose2.Text = timesSheet.GetCellValue(12, row)
            End If
        Next
    End If   
End Sub
 
Upvote 0

Colin Evans

Active Member
Licensed User
Longtime User
Removed the 1 in the closed sub and working, many thanks, I wouldn't have found it just did by process of elimination.

Onto my next problem and ideas why the GPS module goes into erro

Thanks again
 
Last edited:
Upvote 0
Top