Android Question One xCLV and One PCLV Side by Side Accessing Same Item Layout and Same Data

Mahares

Expert
Licensed User
Longtime User
One xCLV and one PCLV side by side accessing the same Items layout which has a label, named LblText Both access the same list data. This code works on the first xCLV, but crashes obviously on the PCLV for good reasons that escape me:
B4X:
Sub LblText_Click
  Dim Index As Int=clv1.GetItemFromView(Sender) ‘line 71
  Dim p As B4XView=clv1.GetPanel(Index)
  Log(p.GetView(0).text)
End Sub
How can you still click the labels on the PCLV without it crashing. I also tried to use: clv1.AsView.Tag=clv1 and clv3.AsView.Tag=clv3
B4X:
Error occurred on line: 71 (Main)
java.lang.ClassCastException: android.view.ViewRootImpl cannot be cast to android.view.View
at anywheresoftware.b4a.objects.B4XViewWrapper.asViewWrapper(B4XViewWrapper.java:88)
at anywheresoftware.b4a.objects.B4XViewWrapper.getParent(B4XViewWrapper.java:185)
 

Mahares

Expert
Licensed User
Longtime User
Use the label tag to store the correct list.
It is the same exact list, same item layout with the same label name for both customlistviews. I will probably have to create 2 separate layouts with a label having a different name in each for each customlistview to make this work and consequently have one.Sub LblText1_Click and another Sub LblText2_Click
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
It is the same exact list
but the objectreferences in the two CLVs are different even if they are based on the same list of data.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
but the objectreferences in the two CLVs are different even if they are based on the same list of data.

Both are populated at the same time: Here is the code to populate the 2 clvs:
B4X:
For Each s As String In MyList
        Dim Pnl As B4XView = xui.CreatePanel("") 'Create a new B4X View
        Pnl.SetLayoutAnimated(0, 0,0, clv1.AsView.Width, 85dip) 'Set the list positiion and dimensions
        Pnl.LoadLayout("Item")
        LblText.Text = s
        clv1.Add(Pnl, s)
        
        PCLV.AddItem(85dip, xui.Color_White, s)        
    Next
 
Upvote 0
Top