#Region Module Attributes
#FullScreen: False
#IncludeTitle: True
#ApplicationLabel: MySQL Example
#VersionCode: 1
#VersionName:
#SupportedOrientations: portrait
#CanInstallToExternalStorage: False
#End Region
'Activity module
Sub Process_Globals
Private COUNTRIES_LIST = "countries_list", COUNTRY_POPULATION = "country_population" As String
End Sub
Sub Globals
Type TwoLines (First As String, Second As String)
Dim lbTelefono As Label
Dim ListView1 As ListView
Dim lbNombre As Label
Dim bt As Button
Dim tx As EditText
Dim Button1 As Button
Dim tx1 As EditText
Dim tx2 As EditText
Dim bt2 As Button
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("1")
ventana
FetchCountriesList
End Sub
Sub FetchCountriesList
' ProgressDialogShow("Fetching list of countries")
'Gets all the available countries
'ExecuteRemoteQuery("SELECT nombre, telefono FROM telefonos ORDER BY nombre", COUNTRIES_LIST)
End Sub
Sub ListView1_ItemClick (Position As Int, Value As Object)
Dim tl As TwoLines
tl = Value
lbTelefono.Text = tl.Second
lbNombre.Text = "Conectando..."
ExecuteRemoteQuery("SELECT nombre, telefono FROM telefonos WHERE nombre='" & tl.First & "'", COUNTRY_POPULATION)
End Sub
Sub ExecuteRemoteQuery(Query As String, JobName As String)
Dim job As HttpJob
job.Initialize(JobName, Me)
job.PostString("http://www.tuweb.com/telefonos.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 COUNTRIES_LIST
Dim COUNTRIES As List
COUNTRIES = parser.NextArray 'returns a list with maps
For i = 0 To COUNTRIES.Size - 1
Dim m As Map
m = COUNTRIES.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("nombre")
tl.Second = m.Get("telefono")
ListView1.AddTwoLines2(tl.First, tl.Second, tl)
Next
Case COUNTRY_POPULATION
Dim l As List
l = parser.NextArray
If l.Size = 0 Then
lbNombre.Text = "s/d"
lbNombre.Text = "..."
Else
Dim m As Map
m = l.Get(0)
lbTelefono.Text=m.Get("telefono")
lbNombre.Text = m.Get("nombre")
End If
End Select
Else
ToastMessageShow("Error: " & Job.ErrorMessage, True)
End If
Job.Release
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub bt_Click
ProgressDialogShow("Buscando...")
'ExecuteRemoteQuery("SELECT nombre, telefono FROM telefonos WHERE nombre like'%" & tx.Text & "%'", COUNTRY_POPULATION)
ListView1.Clear
ExecuteRemoteQuery("SELECT nombre, telefono FROM telefonos WHERE nombre like'%" & tx.Text & "%' ORDER BY nombre", COUNTRIES_LIST)
End Sub
Sub Bt1_Click
ProgressDialogShow("Buscando...")
ListView1.Clear
ExecuteRemoteQuery("SELECT nombre, telefono FROM telefonos WHERE telefono =" & tx1.Text , COUNTRIES_LIST)
End Sub
Sub bt2_Click
ProgressDialogShow("Buscando...")
ListView1.Clear
ExecuteRemoteQuery("SELECT nombre, telefono, domicilio FROM telefonos WHERE domicilio like'%" & tx2.Text & "%' order by domicilio", COUNTRIES_LIST)
End Sub