Sub Process_Globals
Type Postcode( _
County As String, _
Postcode As String, _
Town As String)
Dim Postcodes As List
End Sub
Sub Globals
Dim ListView1 As ListView
End Sub
Sub Activity_Create(FirstTime As Boolean)
ListView1.Initialize("ListView1")
ListView1.FastScrollEnabled=True
Activity.AddView(ListView1, 0, 0, 100%x, 100%y)
If Postcodes.IsInitialized=False Then
Dim XOMBuilder1 As XOMBuilder
XOMBuilder1.Initialize("XOMBuilder1")
XOMBuilder1.BuildFromURL("http://www.bishmedia.co.uk/default/Apps/postcodes.xml", Null)
Else
BuildListView
End If
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub XOMBuilder1_BuildDone(XOMDocument1 As XOMDocument, Tag As Object)
If XOMDocument1=Null Then
' XOMDocument1 will be Null if an error has occurred
Log("An error has occured and the XOMDocument has NOT been created")
' now handle the failure to get and parse the XML
Else
Log("XOMDocument successfully created")
Dim PostcElement As XOMElement=XOMDocument1.RootElement.GetFirstChildElementByName("result")
Dim PostcElements As XOMElements=PostcElement.GetChildElementsByName("postc")
Dim PostcCount As Int=PostcElements.Size
Dim PostcElement As XOMElement
Postcodes.Initialize
Dim i As Int
For i=0 To PostcCount-1
PostcElement=PostcElements.GetElement(i)
Dim Postcode1 As Postcode
Postcode1.Initialize
Postcode1.County=PostcElement.GetFirstChildElementByName("county").Value
Postcode1.Postcode=PostcElement.GetFirstChildElementByName("postcode").Value
Postcode1.Town=PostcElement.GetFirstChildElementByName("town").Value
Postcodes.Add(Postcode1)
Next
BuildListView
End If
End Sub
Sub BuildListView
Dim i As Int
Dim ListTitle As String
Dim Postcode1 As Postcode
' sort the List of Postcode Type by a Postcode field
Postcodes.SortType("Town", True)
For i=0 To Postcodes.Size-1
Postcode1=Postcodes.Get(i)
ListTitle=Postcode1.Town&", "&Postcode1.County&" ("&Postcode1.Postcode&")"
ListView1.AddSingleLine2(ListTitle, Postcode1)
Next
End Sub
Sub ListView1_ItemClick (Position As Int, Value As Object)
Log("ListView1_ItemClick")
Dim Postcode1 As Postcode=Value
Log(Postcode1.Postcode&" "&Postcode1.Town&" "&Postcode1.County)
Log("********************")
End Sub