Android Example Async task help

Gianni4Forum

New Member
Hi expert
i'm trying B4A coming from Appcelerator.
It is very fast and simply

I try to use a scrollview populated from a sqllite db cursor with many records
my scrollview is very slow when loading

For this reason I'm thinking of asynchronous code or other ways

can someone help me please
thank's


the above is my code
Sub AR_Load
Dim ArBitmap As Bitmap
Dim MainPanel As Panel
Dim PanelTop, PanelHeight As Int
Dim progress As Int
Dim Cur as Cursor
Dim Db as SQL
PanelTop = 0
MainPanel = SV_Ar.Panel
MainPanel.Color = Colors.LightGray
db.Initialize(File.DirAssets,"db_sede.db",True)

cur = db.ExecQuery("Select cdar, ar_descrizione from ar")
' this return about 7000 records and is fastest (250 ms)

For i = 0 To 500 ' cur.RowCount - 1 '(only fist 500 records for test)
cur.Position = i
progress = i / 500 * 100
Dim ItemPanel As Panel
Dim ImgAr As ImageView
Dim LblCdAr, LblArDescrizione As Label
LblCdAr.Initialize("")
ArBitmap.Initialize(File.DirAssets,"TREND.png")
ItemPanel.Initialize("")
LblArDescrizione.Initialize("")
PanelHeight = 90dip
MainPanel.AddView(ItemPanel,5dip,PanelTop,SV_Ar.Width,PanelHeight)
ItemPanel.Color = Colors.Black
ItemPanel.AddView(LblCdAr,80dip,8dip,240dip,PanelHeight)

LblCdAr.Color = Colors.Black
LblCdAr.Tag = LblCdAr
LblCdAr.Text = cur.GetString("cdar")
LblCdAr.TextSize = 20
ItemPanel.AddView(LblArDescrizione,80dip,30dip,240dip,30dip)
LblArDescrizione.TextSize = 16
LblArDescrizione.Tag = LblArDescrizione
LblArDescrizione.Text = cur.GetString("ar_descrizione")
ImgAr.Initialize("")
'
ItemPanel.AddView(ImgAr,1dip,5dip,75dip,75dip)
ImgAr.Bitmap = ArBitmap
ImgAr.Gravity = Gravity.FILL
PanelTop = PanelTop + PanelHeight + 1dip
ProgressBar.progress = progress
If i Mod 50 = 0 Then ' refresh progressbar every 50 record
DoEvents
End If
Next
MainPanel.Height=PanelTop
cur.Close
Msgbox("","End Load scrollview")
End Sub
 

Gianni4Forum

New Member
Hi Erel
thank's for your answer
I'm starting with B4a only yesterday.

that i want is a list of product with some product information and product icon
i want insert some filter and need to display result in a listview or scrollview

I imagined that DoEvents would slow the program but I have inserted it to obtain a progressbar refresh and increment because without the above code
B4X:
If i Mod 50 = 0 Then ' refresh progressbar every 50 record
DoEvents
End If
I did not see any movement of it
In addition I have used several times
B4X:
ArBitmap.Initialize( ...
because in my code the name of icon is different for all product

I noticed from forum that you are a real expert, could you give me some help please?
thanks
 

Gianni4Forum

New Member
both on real and emulator!
Can you help me how to reuse img please? i don't know how to do that
thank's


Can you have an Example of Async Task ?
 
Top