Problem with Array

ciginfo

Well-Known Member
Licensed User
Longtime User
Hello,
Why it doesn't work?
ImageView0, ImageView1 etc.. are built with designer
It seems ImageView0, ImageView1 etc.. not initialized

Dim ImageView0, ImageView1, ImageView2, ImageView3, ImageView4 as ImageView
Dim ImgPilule() As ImageView
ImgPilule = Array As ImageView(ImageView0, ImageView1, ImageView2, ImageView3, ImageView4)

Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Main")
ImgPilule(5).Initialize("")
bmp_pilule = LoadBitmap(File.DirAssets, "pilule.png")
ImgPilule(0).Bitmap = bmp_pilule
End sub


Thank you
 

klaus

Expert
Licensed User
Longtime User
Il faut supprimer ImgPilule(5).Initialize("") !

Dim ImageView0, ImageView1, ImageView2, ImageView3, ImageView4 as ImageView
Dim ImgPilule() As ImageView
ImgPilule = Array As ImageView(ImageView0, ImageView1, ImageView2, ImageView3, ImageView4)

Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Main")
bmp_pilule = LoadBitmap(File.DirAssets, "pilule.png")
ImgPilule(0).Bitmap = bmp_pilule
End sub


Du faut que les ImageViews ont été créés
dans le layout, donc déjà initialisées , il ne faut plus les réinitialiser !

Meilleures salutations.

You must remove
ImgPilule(5).Initialize("") !
As the ImageViews are created in the layout, therefore already initialized, they must not be initialized again !

Best regards.

 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Here you are.

From your first post:
B4X:
ImageView0, ImageView1 etc.. are built with designer
No, these ImageViews are not created in the Designer, you have only ImgViewPilule created in the Designer. Therefore ImageView0, ImageView1 etc. must be initialized in the code!
Attached the modified code.
To make my tests I added an image to the Files directory, because pilule.png is missing.

Best regards.
 

Attachments

  • pilule.zip
    13.4 KB · Views: 158
Upvote 0

ciginfo

Well-Known Member
Licensed User
Longtime User
Thank your very much for your answer but I don't understand because ImageView0, ImageView1, etc.. have really been created in the designer, duplicating the first ImageView. So it is the designer which gave the name ImageView0, ImageView1 etc.. or there is a misunderstanding on how to use the designer. This, with the last version of Basic4Android using the new designer.
 
Upvote 0

ciginfo

Well-Known Member
Licensed User
Longtime User
In fact, it is ImgPilule (because an "array") that is not built with the designer and not the ImageView(s). So I can conceive of it.
However, I used the file that you have corrected, ImgPilule is initialized, there is no bug but the image "flag_fr.png" is not displayed in the ImageView corresponding.

bmp_pilule = LoadBitmap(File.DirAssets, "flag_fr.png")
ImgPilule(0).Bitmap = bmp_pilule

It doesn't appear if I write ImgPilule(1) ImgPilule(2) ImgPilule(3) etc..
I don't understand. Does it work with you ?
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Yo are right, I didn't look deeply enough, sorry.
I looked this time more carefully, and the only solution I found yet is to add the ImageViews in the code.

Attached the modified version.

Best regards.
 

Attachments

  • pilule.zip
    13.2 KB · Views: 197
Upvote 0

ciginfo

Well-Known Member
Licensed User
Longtime User
I'm sorry, but I do not understand the code (line 120 to 135).
It seems that I can work on only 19 Imageview, not 21.
Blocks from "ImgPilule (19)."
In fact, I want an array of 21 imagesView and secondarily to change the image independently in each ImageView.
I can not encode correctly, I did not find either examples.
thank you
 

Attachments

  • pilule2.zip
    13.1 KB · Views: 203
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…