Sub airportquery
Dim rs As ResultSet= Main.SQL1.ExecQuery( "SELECT airport FROM " & Main.DBTableplaces & " ORDER BY airport ")
Dim mylist as list
mylist.initialize
Do While rs.NextRow
mylist.Add(rs.GetString("airport")) '7000 airport rows
Loop
SearchTemplateairport.SetItems(mylist)
rs.close
End Sub
Hello Peter..it is a table in a database, not a .txt file, screenshot attached..@harinder you say three seconds, but you do know that can also depend on the speed of the device it's being executed on.
Does your airport data look anything like this?
1,"Goroka Airport","Goroka","Papua New Guinea","GKA","AYGA",-6.081689834590001,145.391998291,5282,10,"U","Pacific/Port_Moresby","airport","OurAirports"
2,"Madang Airport","Madang","Papua New Guinea","MAG","AYMD",-5.20707988739,145.789001465,20,10,"U","Pacific/Port_Moresby","airport","OurAirports"
3,"Mount Hagen Kagamuga Airport","Mount Hagen","Papua New Guinea","HGU","AYMH",-5.826789855957031,144.29600524902344,5388,10,"U","Pacific/Port_Moresby","airport","OurAirports"
4,"Nadzab Airport","Nadzab","Papua New Guinea","LAE","AYNZ",-6.569803,146.725977,239,10,"U","Pacific/Port_Moresby","airport","OurAirports"
5,"Port Moresby Jacksons International Airport","Port Moresby","Papua New Guinea","POM","AYPY",-9.443380355834961,147.22000122070312,146,10,"U","Pacific/Port_Moresby","airport","OurAirports"
6,"Wewak International Airport","Wewak","Papua New Guinea","WWK","AYWK",-3.58383011818,143.669006348,19,10,"U","Pacific/Port_Moresby","airport","OurAirports"
7,"Narsarsuaq Airport","Narssarssuaq","Greenland","UAK","BGBW",61.1604995728,-45.4259986877,112,-3,"E","America/Godthab","airport","OurAirports"
8,"Godthaab / Nuuk Airport","Godthaab","Greenland","GOH","BGGH",64.19090271,-51.6781005859,283,-3,"E","America/Godthab","airport","OurAirports"
9,"Kangerlussuaq Airport","Sondrestrom","Greenland","SFJ","BGSF",67.0122218992,-50.7116031647,165,-3,"E","America/Godthab","airport","OurAirports"
10,"Thule Air Base","Thule","Greenland","THU","BGTL",76.5311965942,-68.7032012939,251,-4,"E","America/Thule","airport","OurAirports"
11,"Akureyri Airport","Akureyri","Iceland","AEY","BIAR",65.66000366210938,-18.07270050048828,6,0,"N","Atlantic/Reykjavik","airport","OurAirports"
12,"Egilsstaðir Airport","Egilsstadir","Iceland","EGS","BIEG",65.2833023071289,-14.401399612426758,76,0,"N","Atlantic/Reykjavik","airport","OurAirports"
13,"Hornafjörður Airport","Hofn","Iceland","HFN","BIHN",64.295601,-15.2272,24,0,"N","Atlantic/Reykjavik","airport","OurAirports"
14,"Húsavík Airport","Husavik","Iceland","HZK","BIHU",65.952301,-17.426001,48,0,"N","Atlantic/Reykjavik","airport","OurAirports"
15,"Ísafjörður Airport","Isafjordur","Iceland","IFJ","BIIS",66.05809783935547,-23.135299682617188,8,0,"N","Atlantic/Reykjavik","airport","OurAirports"
16,"Keflavik International Airport","Keflavik","Iceland","KEF","BIKF",63.985000610352,-22.605600357056,171,0,"N","Atlantic/Reykjavik","airport","OurAirports"
17,"Patreksfjörður Airport","Patreksfjordur","Iceland","PFJ","BIPA",65.555801,-23.965,11,0,"N","Atlantic/Reykjavik","airport","OurAirports"
18,"Reykjavik Airport","Reykjavik","Iceland","RKV","BIRK",64.1299972534,-21.9405994415,48,0,"N","Atlantic/Reykjavik","airport","OurAirports"
19,"Siglufjörður Airport","Siglufjordur","Iceland","SIJ","BISI",66.133301,-18.9167,10,0,"N","Atlantic/Reykjavik","airport","OurAirports"
20,"Vestmannaeyjar Airport","Vestmannaeyjar","Iceland","VEY","BIVM",63.42430114746094,-20.278900146484375,326,0,"N","Atlantic/Reykjavik","airport","OurAirports"
21,"Sault Ste Marie Airport","Sault Sainte Marie","Canada","YAM","CYAM",46.48500061035156,-84.5093994140625,630,-5,"A","America/Toronto","airport","OurAirports"
22,"Winnipeg / St. Andrews Airport","Winnipeg","Canada",\N,"CYAV",50.0564002991,-97.03250122070001,760,-6,"A","America/Winnipeg","airport","OurAirports"
23,"Halifax / CFB Shearwater Heliport","Halifax","Canada",\N,"CYAW",44.639702,-63.499401,144,-4,"A","America/Halifax","airport","OurAirports"
24,"St. Anthony Airport","St. Anthony","Canada","YAY","CYAY",51.3918991089,-56.083099365200006,108,-3.5,"A","America/St_Johns","airport","OurAirports"
25,"Tofino / Long Beach Airport","Tofino","Canada","YAZ","CYAZ",49.079833,-125.775583,80,-8,"A","America/Vancouver","airport","OurAirports"
26,"Kugaaruk Airport","Pelly Bay","Canada","YBB","CYBB",68.534401,-89.808098,56,-7,"A","America/Edmonton","airport","OurAirports"
27,"Baie Comeau Airport","Baie Comeau","Canada","YBC","CYBC",49.13249969482422,-68.20439910888672,71,-5,"A","America/Toronto","airport","OurAirports"
28,"CFB Bagotville","Bagotville","Canada","YBG","CYBG",48.33060073852539,-70.99639892578125,522,-5,"A","America/Toronto","airport","OurAirports"
29,"Baker Lake Airport","Baker Lake","Canada","YBK","CYBK",64.29889678960001,-96.077796936,59,-6,"A","America/Winnipeg","airport","OurAirports"
30,"Campbell River Airport","Campbell River","Canada","YBL","CYBL",49.950801849365234,-125.27100372314453,346,-8,"A","America/Vancouver","airport","OurAirports"
31,"Brandon Municipal Airport","Brandon","Canada","YBR","CYBR",49.91,-99.951897,1343,-6,"A","America/Winnipeg","airport","OurAirports"
32,"Cambridge Bay Airport","Cambridge Bay","Canada","YCB","CYCB",69.1081008911,-105.138000488,90,-7,"A","America/Edmonton","airport","OurAirports"
33,"Nanaimo Airport","Nanaimo","Canada","YCD","CYCD",49.054970224899996,-123.869862556,92,-8,"A","America/Vancouver","airport","OurAirports"
34,"Castlegar/West Kootenay Regional Airport","Castlegar","Canada","YCG","CYCG",49.2963981628,-117.632003784,1624,-8,"A","America/Vancouver","airport","OurAirports"
35,"Miramichi Airport","Chatham","Canada","YCH","CYCH",47.007801,-65.449203,108,-4,"A","America/Halifax","airport","OurAirports"
36,"Charlo Airport","Charlo","Canada","YCL","CYCL",47.990799,-66.330299,132,-4,"A","America/Halifax","airport","OurAirports"
37,"Kugluktuk Airport","Coppermine","Canada","YCO","CYCO",67.816704,-115.143997,74,-7,"A","America/Edmonton","airport","OurAirports"
38,"Coronation Airport","Coronation","Canada","YCT","CYCT",52.0750007629,-111.444999695,2595,-7,"A","America/Edmonton","airport","OurAirports"
39,"Chilliwack Airport","Chilliwack","Canada","YCW","CYCW",49.1528015137,-121.939002991,32,-8,"A","America/Vancouver","airport","OurAirports"
40,"Clyde River Airport","Clyde River","Canada","YCY","CYCY",70.4860992432,-68.5167007446,87,-5,"A","America/Toronto","airport","OurAirports"
41,"Coral Harbour Airport","Coral Harbour","Canada","YZS","CYZS",64.1932983398,-83.3593978882,210,-5,"A","America/Coral_Harbour","airport","OurAirports"
42,"Dawson City Airport","Dawson","Canada","YDA","CYDA",64.04309844970703,-139.1280059814453,1215,-8,"A","America/Vancouver","airport","OurAirports"
43,"Burwash Airport","Burwash","Canada","YDB","CYDB",61.37110137939453,-139.04100036621094,2647,-8,"A","America/Vancouver","airport","OurAirports"
44,"Princeton Airport","Princeton","Canada",\N,"CYDC",49.4681015015,-120.511001587,2298,-8,"A","America/Vancouver","airport","OurAirports"
45,"Deer Lake Airport","Deer Lake","Canada","YDF","CYDF",49.21080017089844,-57.39139938354492,72,-3.5,"A","America/St_Johns","airport","OurAirports"
46,"Dease Lake Airport","Dease Lake","Canada","YDL","CYDL",58.4221992493,-130.031997681,2600,-8,"A","America/Vancouver","airport","OurAirports"
If yes then you should be loading your results into an xCustomListView using lazy loading. That way your MyList can be used to populate the xCustomListView and your list will appear almost instantly, it will not take 3 seconds to load your airport name data.
Search the forum for 'Lazy Loading'.
Plus you should never ever need to populate a list with 7000 items, add some way to add filtering for the end user.
Enjoy...
The purpose of the B4XSearchTemplate is to allow you to filter your data via a built in search box. If you only load 500 records and start the search using an example: If you type 'bi', the search list will display every item that contains 'bi'. If you have items that contain 'bi' in the remaining 6500 records, you will miss them from the search. So it is essential that you have the entire list of 7000 records available to search.How can I load say 500 items initially from db so that it doesen't delay showing the template
That is not terribly bad for 7000 records.It takes 2-3 secs for searchtemplate to be loaded
I don't think that it is related to the visual list items. The slow part is probably the building of the index. Can you upload a text file with the list of airports?I wonder if xCLV with Lazy Loading
I found this Online List. Maybe it helps?Can you upload a text file with the list of airports?
Thanks..I wonder if xCLV with Lazy Loading can be used with a search function
'read the data from the CSV file
Dim su As StringUtils
Dim list As List = su.LoadCSV("C:\Users\H\Downloads\airports.dat", "", ",")
Dim airports As List
airports.Initialize
For Each row() As String In list
airports.Add(row(1))
Next
Dim search As B4XSearchTemplate
search.Initialize
Dim index As Object = search.SetItems(airports) '<--- this is the place where the index is built
Dim ser As B4XSerializator
File.WriteBytes("C:\Users\H\Downloads\index", "", ser.ConvertObjectToBytes(index))
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("1")
dialog.Initialize(Activity)
search.Initialize
Dim ser As B4XSerializator
Dim data() As Byte = File.ReadBytes(File.DirAssets, "index")
ser.ConvertBytesToObjectAsync(data, "ser")
Wait For ser_BytesToObject (Success As Boolean, NewObject As Object)
search.SetIndex(NewObject)
Button1.Enabled = True
End Sub
Sub Button1_Click
Wait For (dialog.ShowTemplate(search, "Yes", "", "Cancel")) Complete (Result As Int)
End Sub
Sub Btnfrom_Click
airportquery
wait for (Dialog.ShowTemplate(SearchTemplateairport, "", "", "CANCEL")) Complete (Result As Int)
If Result = xui.DialogResponse_Positive Then
Dim airport As String =SearchTemplateairport.Selecteditem
Dim sf As StringFunctions
sf.Initialize
btnfrom.xLBL.Text = sf.Left(airport,3)
lblfrom.SetVisibleAnimated(1000,True)
End If
End Sub
Sub airportquery
Dim rs As ResultSet= Main.SQL1.ExecQuery( "SELECT airport FROM " & Main.DBTableplaces & " ORDER BY airport ")
mylist.initialize
Do While rs.NextRow
mylist.Add(rs.GetString("airport"))
Loop
SearchTemplateairport.SetItems(mylist)
rs.close
End Sub
Index time: 806 ms (5654 Items)Best if you upload a small example. BTW, the index time is printed in the logs when you use SetItems.
Sub airportquery
Dim t1 As Long=DateTime.Now
Dim rs As ResultSet= Main.SQL1.ExecQuery( "SELECT airport FROM " & Main.DBTableplaces & " ORDER BY airport ")
mylist.initialize
Do While rs.NextRow
mylist.Add(rs.GetString("airport"))
Loop
Dim t2 As Long=DateTime.Now
Dim dt As Long=t2-t1
Log($"time to create the list ${dt}"$)
SearchTemplateairport.SetItems(mylist)
rs.close
End Sub
btnfrom.xLBL.Text = sf.Left(airport,3)
btnfrom.xLBL.Text = airport.substring2(0,3)
That's not true. However I cannot further help you here as you didn't upload a small project...The delay is being caused(3secs) because searchtemplate invariably loads all 5654 items and can be seen as a list and when user starts typing
Apologies Erel...I was doing a few routes from the airports list and did not find time earlier. Demo attachedThat's not true. However I cannot further help you here as you didn't upload a small project...
I am making some comments after seeing your project, but I leave it up to Erel to better help you and improve upon my comments if he deems necessary, since he asked you for your project:Demo attached
Mine shows up after 1.3 sec for 5654 records on my tablet. You must be using a slightly slower device.appearing time to about 2 secs
It is only meant to display more visible records on the screen by increasing the height. It only increases the height of the panel. To see more visible records, you can do:Adding resize only changes the panel size..template size with choices remain same
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?