Android Time Dialog Tutorial using Basic4Android

Hi! this is my 3rd tutorial on using the Dialogs in B4A. I will introduce another kind of dialog, the Time Dialog. First, you need to create one button and named it Button1. Next, named your layout name as "Main". Declare first your variable in the Sub_Global like this:
  1. Sub Globals
  2. 'These global variables will be redeclared each time the activity is created.
  3. 'These variables can only be accessed from this module.
  4.  
  5. Dim Button1 As Button
  6. Dim bmp As Bitmap
  7. End Sub
I have initialized bmp as Bitmap because I wanted to have an icon to my TimeDialog. Here's the full code for this:
  1. Sub Process_Globals
  2. 'These global variables will be declared once when the application starts.
  3. 'These variables can be accessed from all modules.
  4.  
  5. End Sub
  6.  
  7. Sub Globals
  8. 'These global variables will be redeclared each time the activity is created.
  9. 'These variables can only be accessed from this module.
  10.  
  11. Dim Button1 As Button
  12. Dim bmp As Bitmap
  13. End Sub
  14.  
  15. Sub Activity_Create(FirstTime As Boolean)
  16. 'Do not forget to load the layout file created with the visual designer. For example:
  17. 'Activity.LoadLayout("Layout1")
  18. Activity.LoadLayout("Main")
  19. bmp.InitializeSample(File.DirAssets, "bermoy.jpg",48,48)
  20. Activity.Title = "Time Dialog - Lyndon Bermoy"
  21.  
  22. End Sub
  23.  
  24. Sub Activity_Resume
  25.  
  26. End Sub
  27.  
  28. Sub Activity_Pause (UserClosed As Boolean)
  29.  
  30. End Sub
  31.  
  32. Sub Button1_Click
  33. Dim td As TimeDialog
  34. Dim txt As String
  35. Dim ret As Object
  36. td.Hour = DateTime.GetHour(DateTime.Now)
  37. td.Minute = DateTime.GetMinute(DateTime.Now)
  38. td.Is24Hours = True
  39. ret = td.Show("Set the required time", "B4A Time Dialog", "Yes", "No", "Maybe", bmp)
  40. ToastMessageShow(ret & " : " & td.Hour & ":" & td.Minute, False)
  41. End Sub
Note: td - used as my variable for TimeDialog txt - used as my variable for String ret - used as my variable for Object td.Hour = DateTime.GetHour(DateTime.Now) - my syntax used to get the hour at this moment. td.Minute = DateTime.GetMinute(DateTime.Now) - my syntax used to get the minute at this moment. td.Is24Hours = True - syntax used to determine if you want to configure the time in 24hours. For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below. Best Regards, Engr. Lyndon Bermoy IT Instructor/System Developer/Android Developer/Freelance Programmer Mobile: 09488225971 Landline: 826-9296 E-mail:[email protected] Add and Follow me on Facebook: https://www.facebook.com/donzzsky Visit and like my page on Facebook at: https://www.facebook.com/BermzISware

Add new comment