Bug? CLV - pnl.GetView(x) Error?

ilan

Expert
Licensed User
Longtime User
hi

i am not sure if it is a bug but when i create a layout and put in it a panel and then in that panel i put for example label, imageview and button.

no i create a new customlistview item and load that layout to the clv item (i am using CustomView)

now when i want to get the view (imageview) that index is 2 because panel index 0, label = 1, imageview =2, button = 3

i get the error that the view is not intialize. but i dont need to intialize it since it is added via designer.
if i remove all view out of the panel and set their Parent to activity then it is working.

only if their Parent is something else then the activity i get the error that it is not intialized.

so only views with the Parent (Activity) are intilizied all other not.

am i doing something wrong or is it a bug?

thanx, ilan
 

klaus

Expert
Licensed User
Longtime User
now when i want to get the view (imageview) that index is 2 because panel index 0, label = 1, imageview =2, button = 3/
Are you sure ?
I would say that label = 0, imageview =1, button = 2 of the Panel.
The Panel has another index in its container view.
 

ilan

Expert
Licensed User
Longtime User
Are you sure ?
I would say that label = 0, imageview =1, button = 2 of the Panel.
The Panel has another index in its container view.

thank you for your answer klaus but the panel has index 0

and because the panel Parent is Activity it is the only view that is intialized and i can do with him any changes i would like
but all views that are inside that panel are not intialized.

just to avoid any confusion, i am not talking about the panel that the clv creates on every CreateListItem, i am talking about the panel that i place in my layout and all other views in that panel

so what will happen when i create a new clv item is that it will load that layout including the panel and all views inside. and only the panel (because his Parent is Activity) is intilalized but all views in that panel are not. and if i intialize them again i loose all settings i set to them in the designer.
 

ilan

Expert
Licensed User
Longtime User
yes

this is erels example the ONLY thing i changed is putting all views in designer to a panel
If you will remove them from the panel so all are in parent "Activity" you will see that it will work
 

Attachments

  • CustomListView.zip
    6.8 KB · Views: 224

klaus

Expert
Licensed User
Longtime User
Code in your example:
B4X:
Sub Button1_Click
    Dim index As Int = clv2.GetItemFromView(Sender)
    Dim pnl As Panel = clv2.GetPanel(index)
    Dim lbl As Label = pnl.GetView(0)
    Dim chk As CheckBox = pnl.GetView(2)
    lbl.Text = "Clicked!"
    Msgbox("Item value: " & clv2.GetValue(index) & CRLF & "Check value: " & chk.Checked, "")
End Sub
New code:
B4X:
Sub Button1_Click
    Dim index As Int = clv2.GetItemFromView(Sender)
    Dim pnl As Panel = clv2.GetPanel(index)
    Dim pnl1 As Panel = pnl.GetView(0)
    Dim lbl As Label = pnl1.GetView(0)
    Dim chk As CheckBox = pnl1.GetView(2)
    lbl.Text = "Clicked!"
    Msgbox("Item value: " & clv2.GetValue(index) & CRLF & "Check value: " & chk.Checked, "")
End Sub

The problem in your code is the fact that pnl is the base Panel in the CustomListView.
pnl.GetView(0) returns the Panel of the layout. This is the only view in the base panel.
To get the views of the layout panel you must define it with:
Dim pnl1 As Panel = pnl.GetView(0)
and the other views with
pnl1.GetView(x)
which are child views of pnl1 and not pnl.
Attached a modified version of your example project.
 

Attachments

  • CustomListView1.zip
    11.1 KB · Views: 220

ilan

Expert
Licensed User
Longtime User
Code in your example:
B4X:
Sub Button1_Click
    Dim index As Int = clv2.GetItemFromView(Sender)
    Dim pnl As Panel = clv2.GetPanel(index)
    Dim lbl As Label = pnl.GetView(0)
    Dim chk As CheckBox = pnl.GetView(2)
    lbl.Text = "Clicked!"
    Msgbox("Item value: " & clv2.GetValue(index) & CRLF & "Check value: " & chk.Checked, "")
End Sub
New code:
B4X:
Sub Button1_Click
    Dim index As Int = clv2.GetItemFromView(Sender)
    Dim pnl As Panel = clv2.GetPanel(index)
    Dim pnl1 As Panel = pnl.GetView(0)
    Dim lbl As Label = pnl1.GetView(0)
    Dim chk As CheckBox = pnl1.GetView(2)
    lbl.Text = "Clicked!"
    Msgbox("Item value: " & clv2.GetValue(index) & CRLF & "Check value: " & chk.Checked, "")
End Sub

The problem in your code is the fact that pnl is the base Panel in the CustomListView.
pnl.GetView(0) returns the Panel of the layout. This is the only view in the base panel.
To get the views of the layout panel you must define it with:
Dim pnl1 As Panel = pnl.GetView(0)
and the other views with
pnl1.GetView(x)
which are child views of pnl1 and not pnl.
Attached a modified version of your example project.


this make sense, thank you :)
 
Top