Android Question LoadBitmap in array of ImageView

Oldmanenzo

Member
Licensed User
Longtime User
I have the need to load a variable number of ImageView in a panel. I tried using two way but in both cases is the same error occurs, or the loading of the second image from an exception error FileNotFound (name file.png).
At first I thought of an error in the file name, but failing to find no error I tried to change the order (bar, market in this case the bar is loaded, market goes wrong) instead of using (market, bar in this case market is loaded bar goes wrong).
In the first case I used an array of images, in the second case a list of images
The variable "servizi" contains entries of images

B4X:
Dim img(servizi.lenght) as imageview
For n=0 to servizi.lenght -1
    img(n).initialize(“img”)
    img.Gravity =Gravity.FILL  
    img.Bitmap =LoadBitmap(File.DirAssets ,servizi(n) &".png") 'Error when load second image
    Pnl.AddView (img, valuex, valuey, 30dip, 30dip)      
    img.Tag =n
valuex=valuex+35
‘Second line of images
If n=9 then
    Valuex=7 : valuey=40
End if
Next

this is the second way using a list

B4X:
For j=0 To servizi.Length -1
        Dim img As ImageView
        img.Initialize ("img")
        img.Bitmap =LoadBitmap(File.DirAssets ,servizi(j) &".png") 'Error when load second image
        ImgList.Add (img)
    Next

I hope that the solution is not the type

B4X:
Dim img1 as ImageView
Dim img2 as ImageView
……
…..
…..
Dim img20 as Imageview

I forgot to say that all the images are loaded into serving designer of Activity
 

DonManfred

Expert
Licensed User
Longtime User
servizi is a list of strings which holds the filenames?
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Shouldn't the code be this ?
B4X:
For n=0 to servizi.lenght -1
    img(n).initialize(“img”)
    img(n).Gravity =Gravity.FILL
    img(n).Bitmap =LoadBitmap(File.DirAssets ,servizi(n) &".png") 'Error when load second image
    Pnl.AddView (img(n), valuex, valuey, 30dip, 30dip)   
    img(n).Tag =n
Put Log(servizi(n)) just before img(n).Bitmap = ... and a breakpoint in img(n).Bitmap = ... and check the value of servizi(n) and look what happens.
 
Upvote 0

Oldmanenzo

Member
Licensed User
Longtime User
Shouldn't the code be this ?
B4X:
For n=0 to servizi.lenght -1
    img(n).initialize(“img”)
    img(n).Gravity =Gravity.FILL
    img(n).Bitmap =LoadBitmap(File.DirAssets ,servizi(n) &".png") 'Error when load second image
    Pnl.AddView (img(n), valuex, valuey, 30dip, 30dip)  
    img(n).Tag =n
Put Log(servizi(n)) just before img(n).Bitmap = ... and a breakpoint in img(n).Bitmap = ... and check the value of servizi(n) and look what happens.
Yes klaus code is entered, missing three rows and are as follows
after img(n).tag = n
valuex =valuex + 35
for the second row of images
if n => 9 then
valuex = 7: valuey = 40
next

and of course before entering the loop " for....next"
Dim img (servizi.lenght) as ImageView

the names are stored in a table separated by commas and regex.split revenue the variable "servizi"
if the first column contains "bar, market" in this case the bar is loaded and market it faults
I try with another column where it is stored "market, bar" in this case bar fails, while in the previous case no.
Honestly I do not know what to think
 
Upvote 0

Oldmanenzo

Member
Licensed User
Longtime User
HIP HIP yahoooo
I think I found the error, stupid but definitely always a mistake.
in the field is stored in this way
"bar, market", swimming pool, restaurant "
when I run regex split comes out this
bar
(space) market
(space) swimming pool
(space) restaurant
in fact there is a space at the beginning of the name and the first name does not have space here is the reason why the second onwards was in error.
at this point I memorize or "bar, market", swimming pool" without spaces or delete
after regex.split
 
Upvote 0
Top