Android Question listview takes more time

gjoisa

Active Member
Licensed User
Longtime User
In my app , there are 29 lines with bitmap . It takes more than 40 seconds to load . If it is without bitmap , loads faster . Is it natural behaviour ?
 

gjoisa

Active Member
Licensed User
Longtime User
It is not really related to ListView. Are you using LoadBitmapSample?
This is my code :
B4X:
Dim str() As String
          Dim distname() As String
    str=(Array As String("bagalkot.jpg","bangalore.jpg","belgaum.jpg","bellary.jpg","Bidar.jpg","bijapur.jpg","chamrajnagar.jpg", _
    "chikballapur.jpg","chikkamagaloor.jpg","chitradurga.jpg","mangalore.jpg","davangere.jpg","dharwad.jpg","gadag.jpg", _
    "gulbarga.jpg","hassan.jpg","haveri.jpg","kodagu.jpg","kolar.jpg","koppal.jpg","mandya.jpg","mysore.jpg","raichur.jpg", _
    "ramadevara-betta.jpg","shimoga.jpg","Aralaguppe-temple.jpg","udupi.jpg","karwar.jpg","vanadurga.jpg"))
   
distname=(Array As String("Bagalkot","Bengaluru","Belgaum","Bellary","Bidar","Bijapur","Chamrajnagar","Chikballapur", _
    "Chikmagalur","Chitradurga","Dakshina Kannada","Davangere","Dharwad","Gadag","Gulbarga","Hassan","Haveri","Kodagu", _
    "Kolar","Koppal","Mandya","Mysore","Raichur","Ramanagara","Shimoga","Tumkur","Udupi","Uttara Kannada","Yadgir"))
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Main")

If FirstTime Then
    For i=0 To str.Length-1
        File.Copy(File.DirAssets,str(i),File.DirRootExternal,str(i))
       
    Next
    End If

For i = 0 To str.Length-1
        listMain.AddTwoLinesAndBitmap(distname(i),"",LoadBitmap(File.DirRootExternal,str(i)))
Next

all jpg files are added to files folder .
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. Check whether the target file exists before copying it from the assets file.
2. Use LoadBitmapSample instead of LoadBitmap.
3. If you allow orientation changes then it is recommended to load the bitmaps once and store them in a process global List (not ListView) and then fill the ListView each time from the list.

4. Test it on a real device. The emulator can be very slow.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…