'Activity module
Sub Process_Globals
Private LIST_CATCH As String
End Sub
Sub Globals
Type TwoLines (First As String, Second As String)
Dim ViewCatchersList As ListView
Private ExitBtn As Button
Private NameSurnametxt As EditText
Private AddressTxt As EditText
Private AddBtn As Button
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Main")
FetchNamesList
End Sub
Sub FetchNamesList
ProgressDialogShow("Fetching list of Name")
ExecuteRemoteQuery("SELECT NameSurname, Address FROM catchers ", LIST_CATCH)
End Sub
Sub ExecuteRemoteQuery(Query As String, JobName As String)
Dim job As HttpJob
job.Initialize(JobName, Me)
job.PostString("http://www.xxxx.co.za/get.php", Query)
End Sub
Sub JobDone(Job As HttpJob)
ProgressDialogHide
If Job.Success Then
Dim res As String
res = Job.GetString
Log("Response from server: " & res)
Dim parser As JSONParser
parser.Initialize(res)
Select Job.JobName
Case LIST_CATCH
Dim GetCatchList As List
GetCatchList = parser.NextArray 'returns a list with maps
For i = 0 To GetCatchList.Size - 1
Dim m As Map
m = GetCatchList.Get(i)
'We are using a custom type named TwoLines (declared in Sub Globals).
'It allows us to later get the two values when the user presses on an item.
Dim tl As TwoLines
tl.First = m.Get("Address")
tl.Second = m.Get("NameSurname")
ViewCatchersList.AddTwoLines2(tl.First, tl.Second, tl)
Next
Case "INSERT_CATCH"
'print the result to the logs
Log(Job.GetString)
End Select
Else
ToastMessageShow("Error: " & Job.ErrorMessage, True)
End If
Job.Release
End Sub
Sub ExitBtn_Click
Activity.Finish
End Sub
Sub AddBtn_Click
Dim InsCatchers As HttpJob
InsCatchers.Initialize("INSERT_CATCH", Me)
InsCatchers.Download2("http://www.xxx.co.za/ins.php", Array As String("NameSurname", NameSurnametxt.text, "Address", AddressTxt.text))
End Sub