Android Question using layout files with customlistview's panels?

leitor79

Active Member
Licensed User
Hi,

I'm loading a customlistview with manually configured panels, each with several addviews. It's kinda a mess to arrange them using top, left, width, height.

I've been looking here and I've found references about users using layouts to load panels (questions asked and answered), "Panel.LoadLayout...", but what I can't find is how to access the loaded layout components.

Let's say my "Layout1" has 2 labels, "Label1" and "Label2". How do I do something like this?

B4X:
Panel.LoadLayout("Layout1")
Panel.Label1="Hello"
Panel.Label2="World"
(I know it can't be done like this, it's an example of what I want to achieve)

Regards!
 

leitor79

Active Member
Licensed User
Hi klaus,
thank you for your answer.

My panel has several labels and imageviews. And I don't like the idea of relying on an index; if I add or remove a view I have to fix all the indexes... and how I noew the indexes? They always corresponds to the order above the tree in the designer?

Thank you very much!
 

Erel

Administrator
Staff member
Licensed User
There are all kinds of ways to access these views.

One simple way is to declare global variables for these views. When you load the layout file the variables will reference the last set of views that were loaded.
For example:
B4X:
For i = 1 To 100
 Panel1.LoadLayout(...)
 Label1.Text = "Text"
Next
If you want to access the views at a later stage you can declare a custom type:
B4X:
Type ItemViews (lbl As Label, btn As Button)
B4X:
For i = 1 To 100
 Panel1.LoadLayout(...)
 Dim iv As ItemViews
 iv.Initialize
 iv.lbl = Label1
 iv.btn = Button1
 Label1.Text = "Text"
 Panel1.Tag = iv
Next
Later you can access the views:
B4X:
Dim iv As ItemViews = Panel1.Tag
iv.lbl.Text = "sdfsdf"
 

RandomCoder

Well-Known Member
Licensed User
Nice, I've never thought of storing anything other than a string for the Tag value. I'm sure I'll use this in new projects!
 

qsrtech

Active Member
Licensed User
There are all kinds of ways to access these views.

One simple way is to declare global variables for these views. When you load the layout file the variables will reference the last set of views that were loaded.
For example:
B4X:
For i = 1 To 100
Panel1.LoadLayout(...)
Label1.Text = "Text"
Next
If you want to access the views at a later stage you can declare a custom type:
B4X:
Type ItemViews (lbl As Label, btn As Button)
B4X:
For i = 1 To 100
Panel1.LoadLayout(...)
Dim iv As ItemViews
iv.Initialize
iv.lbl = Label1
iv.btn = Button1
Label1.Text = "Text"
Panel1.Tag = iv
Next
Later you can access the views:
B4X:
Dim iv As ItemViews = Panel1.Tag
iv.lbl.Text = "sdfsdf"
and just to confirm you use the original event and then find the sender within the itemviews?
 
Top