First of all, let me say that I am a newbie to Basic 4 Android but before posting this I have read all the examples I could find on the forum, I purchased the new and excellent book on this language and environment but I am still stumped.
The basics of what I am trying to do is read records from a database using the "ExecuteMap" command and then display them in a label based on the position of a "SeekBar"
I only have one record in the table currently for testing so I am not trying to loop through a set of values yet but to read the single record, display it in the label for testing.
I have included all my code but the area I am having the issue is in the read routine. I think I am just not understand how to retrieve the values and then assign them to the label. Please look at the "ReadPrjListTable" Sub and let me know where I am approaching this incorrectly.
The basics of what I am trying to do is read records from a database using the "ExecuteMap" command and then display them in a label based on the position of a "SeekBar"
I only have one record in the table currently for testing so I am not trying to loop through a set of values yet but to read the single record, display it in the label for testing.
I have included all my code but the area I am having the issue is in the read routine. I think I am just not understand how to retrieve the values and then assign them to the label. Please look at the "ReadPrjListTable" Sub and let me know where I am approaching this incorrectly.
B4X:
#Region Project Attributes
#ApplicationLabel: My World
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: False
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim DBMyWorld As SQL
Dim prjListMap As Map
prjListMap.Initialize
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim ImageView1 As ImageView
Dim pnlHdrmain As Panel
Dim btnAnalytics As Button
Dim btnProject As Button
Dim btnReports As Button
Dim btnTasks As Button
Dim panelNotifications As Panel
Dim panelPrjViews As Panel
Dim panelProjects As Panel
Dim btnAddNew As Button
Dim btnDelete As Button
Dim btnEdit As Button
Dim btnSettings As Button
Dim panelActions As Panel
Dim lblTitle As Label
Dim labelProject As Label
Dim lblProjectsLst As Label
Dim prjListSeekBar As SeekBar
Dim prjListArray() As String
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("myworldmain")
'Set SeekBar Value to 0
prjListSeekBar.Value = 0
'Test if this is the first time for the application to run and if so, create and initialize the database.
If FirstTime Then
If File.Exists(File.DirDefaultExternal, "MyWorld.db") = False Then
CreatePrjListTable
ReadPrjListTable
Else
ReadPrjListTable
End If
End If
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub CreatePrjListTable
'If Table Doesn't Exist (FirstTime = True) Then Create Table, If (FirstTime = False) Do Nothing.
DBMyWorld.Initialize(File.DirDefaultExternal, "MyWorld.db", True)
prjListMap.Put("prjID", DBUtils.DB_INTEGER)
prjListMap.Put("prjName", DBUtils.DB_TEXT)
DBUtils.CreateTable(DBMyWorld,"ProjectList",prjListMap,"prjID")
prjListMap.Put("prjName","ITOE Redesign for 2013")
End Sub
Sub ReadPrjListTable
Dim prjCnt As Int
Dim prjTotalRecords As Int
DBMyWorld.Initialize(File.DirDefaultExternal, "MyWorld.db", True)
prjTotalRecords = DBMyWorld.ExecQuerySingleResult("SELECT COUNT(*) FROM ProjectList")
prjListMap = DBUtils.ExecuteMap("SELECT prjID, prjName FROM ProjectList", Null)
If prjTotalRecords = Null Then
labelProject.Text = "No Projects Defined!"
Else
labelProject.Text = prjListMap.Get("prjName")
End If
End Sub
Sub prjListSeekBar_ValueChanged (Value As Int, UserChanged As Boolean)
'Set Label for Project Name to Current Record
Dim recPosition As Int
If prjListSeekBar.Value > 0 Then
recPosition = prjListSeekBar.Value
labelProject.Text = prjListMap.Get("prjName")
End If
End Sub