Hello, i am noticing an extremely slow response while executing the following pseudocode.
Every search can pontentially hold more than 1000 results, if i load 1000 rows at begin the app become irresponsive so for that at begin when i start the activity, i execute the query to populate the customlistview with a limit set to 20.
After scrolling down and reaching the bottom i load more 20 rows by increasing the query limit.
It works, but is damn slow.
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
When the listview position reach the bottom i execute this sub
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
This sub is inside customlistview class:
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
			
			Every search can pontentially hold more than 1000 results, if i load 1000 rows at begin the app become irresponsive so for that at begin when i start the activity, i execute the query to populate the customlistview with a limit set to 20.
After scrolling down and reaching the bottom i load more 20 rows by increasing the query limit.
It works, but is damn slow.
			
				B4X:
			
		
		
		Sub Globals
   Private queryLimit As Int = 10
End Sub
Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("listview")
   lst_customlistview.Initialize(Me, "lst_customlistview")
   Activity.AddView(lst_customlistview.AsView, 0, 60dip , 100%x, 100%y -60dip)
fetchDB(queryLimit, False)
End Sub
Sub fetchDB(query_Limit As Int, loadMore As Boolean)
     Dim quote_text As String
     If loadMore = False Then
  cursor2 = Main.SQL1.ExecQuery("SELECT ID, fruit, icecream, snacks, starred FROM tablename WHERE fruit LIKE '%" & Main.keywords &"%' OR icecream LIKE '%" & Main.keywords &"%' ORDER BY ID DESC limit "&queryLimit&";")
     Log("True!")
     Else
     ProgressDialogShow2("Loading more results please wait....", False)
     cursor2 = Main.SQL1.ExecQuery("SELECT ID,fruit, icecream, snacks, starred FROM tablename WHERE fruit LIKE '%" & Main.keywords &"%' OR icecream LIKE '%" & Main.keywords &"%' AND id > "&queryLimit&" ORDER BY ID DESC limit "&queryLimit&";")
     Log("false!")
     End If
 
     For i = 0 To cursor2.RowCount - 1
     cursor2.Position = i
     quote_text = cursor2.GetString("fruit")
 
     If quote_text.Length < PreviewMaxLenght Then
     quote_text = quote_text.SubString2(0,quote_text.Length)&"....continue reading"
     Else If quote_text.Length > PreviewMaxLenght Then
     quote_text = quote_text.SubString2(0,PreviewMaxLenght)&"....continue reading"
     End If
   
      Header.Initialize("{White}{B}data: "&cursor2.GetString("snacks")&" - "&cursor2.GetString("starred")&"{B}{White}")
       Header.Color2(Colors.White,"{White}")
       Header.Style2(Header.STYLE_BOLD, "{B}" )
      Entry.Initialize("{Grey}data:"&cursor2.GetString("fruit") &" / data:"&cursor2.GetString("fruit")&"'' / data:"&cursor2.GetString("icecream")&CRLF&"Date:"&cursor2.GetString("snack")&"{Grey}")
       Entry.Color2(Colors.Green,"{Green}")
       Entry.Color2(Colors.RGB(221,221,221),"{Grey}")
       Entry.Style2(Entry.STYLE_BOLD, "{B}" )
   
   
           Dim p As Panel
           p.Initialize("")
           p.Color = Colors.ARGB(255,0,0,0)
           lst_customlistview.Add(p,75dip, 10)
           p.LoadLayout("clvlayout")
           Label1.Color = Colors.RGB(0,0,0)
           Label2.Color = Colors.RGB(0,0,0)
           Label1.Text = Header
           Label2.Text = Entry
           Label1.Typeface = Typeface.LoadFromAssets("font_1.otf")
           Label2.Typeface = Typeface.LoadFromAssets("font_2.otf")
Next
if loadmore = True Then 
ProgressDialogHide
End if
End sub
	When the listview position reach the bottom i execute this sub
			
				B4X:
			
		
		
		Sub lst_customlistview_AddItems
  Log("AddItems")
  queryLimit = queryLimit + queryLimit
  fetchDB(queryLimit, True)
End Sub
	This sub is inside customlistview class:
			
				B4X:
			
		
		
		Private Sub SV_ScrollChanged(Position As Int)
  If Position + sv.Height >= sv.Panel.Height Then
  If DateTime.Now > lastAddItemsTime + 200 Then
  lastAddItemsTime = DateTime.Now
  CallSub(CallBack, EventName & "_AddItems")
  End If
  End If
End Sub
	
			
				Last edited: