Android Question CustomlistView and pnl.GetView

Scantech

Well-Known Member
Licensed User
Longtime User
Here is the following code from CustomlistView example. I am interested with Dim chk As B4XView = pnl.GetView(2).

In the cellitem designer, there appears 3 views (label, button and checkbox). How do i change the view index order of pnl.GetView(x)? Do i have to delete all of the views in the designer and choose the views to add in order of index? The properties does not have the index in the designer. Is there a simple way of doing this?

B4X:
Sub CheckBox1_CheckedChange(Checked As Boolean)
    Dim index As Int = clv2.GetItemFromView(Sender)
    Dim pnl As B4XView = clv2.GetPanel(index)
    Dim chk As B4XView = pnl.GetView(2)
    MsgboxAsync($"Item value: ${clv2.GetValue(index)}
Check value: ${chk.Checked}"$, "")
End Sub
 

mangojack

Well-Known Member
Licensed User
Longtime User
@LucaMs is correct. I have dragged / swapped the position of the views in the Designer view tree, resulting in an CLV.panel index change reference.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I have dragged / swapped the position of the views in the Designer view tree, resulting in an CLV.panel index change reference.
Hi mj:
I used this code on one of my projects. I show the checkbox as item 0 and it worked fine, but on the designer tree it is shown 3rd:
B4X:
Sub CheckBox1_CheckedChange(Checked As Boolean)    
    Dim index As Int = clv2.GetItemFromView(Sender)
    Dim pnl As B4XView = clv2.GetPanel(index)
    Dim chk As B4XView = pnl.GetView(0)  'referring to this as item0 works for me
    MsgboxAsync($"Item value: ${clv2.GetValue(index)}
    Check value: ${chk.Checked}"$, "")
End Sub
 

Attachments

  • DesignerAndTree.PNG
    DesignerAndTree.PNG
    19 KB · Views: 190
Upvote 0

mangojack

Well-Known Member
Licensed User
Longtime User
I used this code on one of my projects. I show the checkbox as item 0 and it worked fine, but on the designer tree it is shown 3rd:

Interesting ... I have always used / swapped around the View Tree order to align / neaten code when say reading / writing to db data to and from views.
although to view display will be completely different order.

Should the referred view index be different from the View Tree order , an error is thrown.

Even in the XCustomListView example (which has a layout similar in order to your above layout ... CheckBox = 3rd View) ... references GetView(2)
B4X:
Dim chk As B4XView = pnl.GetView(2)


Maybe @Erel can shed some light.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I used this code on one of my projects. I show the checkbox as item 0 and it worked fine, but on the designer tree it is shown 3rd:
Sorry, but I cannot believe this.
I tested several times moving a view in the Views Tree and the indexes with GetView are in the order in the Views Tree.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Sorry, but I cannot believe this.
unless you called BringToFront or SendToBack at runtime.
what @Mahares did will always give False value
Here are my findings: The order in the tree is: Label1, Edt and Checkbox1. When I run my project the checkbox is referred to as: pnl.GetView(0) and returns TRUE when checked, although it is shown as second in the designer tree. Label1 is an AutoTextSizeLabel custom view, not a regular label. Perhaps custom views do not figure in the tree order. So, what I did is recreate the same project by replacing the AutoTextSizeLabel with a regular Label, and with the same order as what I used when the AutoTextSizeLabel was used, the tree order was respected and the checkbox was: pnl.GetView(1) and returns TRUE.
It looks like a custom view does not figure in the tree order. I can, if someone wants proof post a project. Perhaps Erel can explain better
 
Upvote 0
Top