array of views in designer

anuj0sharma

Member
Licensed User
Longtime User
how can i create an array of views in designer?
e.g. I am using 10 imageViews in a layout file. i want to create an array out of that for easy access in a loop.

regards,
 

anuj0sharma

Member
Licensed User
Longtime User
Edit to post 1

there are 24 imageViews in 4 different layouts [6x4 = 24]
i want to acess all thease views through program. how can I create an array of all there image views.?

e.g. these are the 6 imageViews used in one of the layout and i want to create array of these..its not working.


B4X:
Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   
   Dim blueLamp1 As ImageView
      blueLamp1.Initialize("")
   Dim blueLamp2 As ImageView
      blueLamp2.Initialize("")
   Dim blueLamp3 As ImageView
      blueLamp3.Initialize("")
   Dim blueLamp4 As ImageView
      blueLamp4.Initialize("")
   Dim blueLamp5 As ImageView
      blueLamp5.Initialize("")
   Dim blueLamp6 As ImageView
      blueLamp6.Initialize("")
   
   Dim blueLampArr(6) As ImageView 
   
End Sub

Sub Activity_Create(FirstTime As Boolean)
   blueLampArr = Array As imageView(blueLamp1,blueLamp2,blueLamp3,blueLamp4,blueLamp5,blueLamp6)
End Sub


now..

B4X:
blueLampArr(0).Bitmap = LoadBitmap(File.DirAssets,"on.gif")

this should change the bitmap for the imageView "blueLamp1"..its not working here. pls help.

regards,
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
If you have created the views in the designer then you do not need to initialize the views yourself.
Instead load the layout file (Activity.LoadLayout) and then assign the views with the array keyword.

Note that you can declare the array variable like this:
B4X:
Dim blueLampArr() As ImageView
It will create an empty array. Later you are assigning a new array instead of the old one.
 
Upvote 0
Top